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 { $currentMinorVersion = $this->extractMinorVersion($this->version); $latestMinorVersion = $this->extractMinorVersion($latestVersion->version); } catch (InvalidVersionNumberException $e) { // Could not parse a semver version number. return false; } return $currentMinorVersion === $latestMinorVersion; } /** * Extract the minor version from a full version string. * * @throws InvalidVersionNumberException */ private function extractMinorVersion(string $version): int { // 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 the minor version part. return (int) $parts[1]; } }