hasMany(ModVersion::class); } /** * Determine if the version is the latest minor version. */ public function isLatestMinor(): bool { $latestSptVersionService = App::make(LatestSptVersionService::class); $latestVersion = $latestSptVersionService->getLatestVersion(); if (! $latestVersion) { return false; } try { [$currentMajor, $currentMinor, $currentPatch] = $this->extractVersionParts($this->version); [$latestMajor, $latestMinor, $latestPatch] = $this->extractVersionParts($latestVersion->version); } catch (InvalidVersionNumberException $e) { return false; } return $currentMajor == $latestMajor && $currentMinor === $latestMinor; } /** * Extract the version components from a full version string. * * @throws InvalidVersionNumberException */ private function extractVersionParts(string $version): array { // Remove everything from the version string except the numbers and dots. $version = preg_replace('/[^0-9.]/', '', $version); // Validate that the version string is a valid semver. if (! preg_match('/^\d+\.\d+\.\d+$/', $version)) { throw new InvalidVersionNumberException; } $parts = explode('.', $version); return [ (int) $parts[0], (int) $parts[1], (int) $parts[2], ]; } }