From 4c9508074fb7c58f8308258409c3636f8127d872 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 9 Oct 2026 20:02:27 +0400 Subject: [PATCH] refactor: fix psalm 6 issues The issues are fixed in code rather than suppressed. ClassMustBeFinal is disabled in psalm.xml: making public classes final would break BC. The JetBrains ExpectedValues suppression is dropped because nothing uses that attribute any more. Assisted-By: Claude Opus 5.5 --- psalm.xml | 6 +----- src/Composer/Package.php | 8 +++++++- src/Environment/Native.php | 1 + src/Process/Process.php | 1 + src/Process/ProcessInterface.php | 3 +++ src/Version/Comparator.php | 3 +++ src/Version/Installed.php | 7 ++++--- src/Version/Required.php | 1 + src/VersionChecker.php | 10 ++++------ 9 files changed, 25 insertions(+), 15 deletions(-) diff --git a/psalm.xml b/psalm.xml index 967944d..8f08fd5 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,10 +14,6 @@ - - - - - + diff --git a/src/Composer/Package.php b/src/Composer/Package.php index f2824c8..bec0ec1 100644 --- a/src/Composer/Package.php +++ b/src/Composer/Package.php @@ -13,14 +13,20 @@ final class Package implements PackageInterface * @param non-empty-string $packageName * @return non-empty-string[] */ + #[\Override] public function getRequiredVersions(string $packageName): array { $versions = []; foreach (InstalledVersions::getInstalledPackages() as $package) { $path = InstalledVersions::getInstallPath($package); if ($path !== null && \file_exists($path . '/composer.json')) { + $content = \file_get_contents($path . '/composer.json'); + if ($content === false) { + continue; + } + /** @var array{require?: array} $composerJson */ - $composerJson = \json_decode(\file_get_contents($path . '/composer.json'), true); + $composerJson = \json_decode($content, true); if ( isset($composerJson['require'][$packageName]) && diff --git a/src/Environment/Native.php b/src/Environment/Native.php index 53daee7..bf3fe32 100644 --- a/src/Environment/Native.php +++ b/src/Environment/Native.php @@ -15,6 +15,7 @@ public function __construct( /** * @param non-empty-string $name */ + #[\Override] public function get(string $name, mixed $default = null): mixed { return $this->values[$name] ?? $default; diff --git a/src/Process/Process.php b/src/Process/Process.php index 1d88c16..c987e40 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -8,6 +8,7 @@ final class Process implements ProcessInterface { + #[\Override] public function exec(array $command): string { $process = new \Symfony\Component\Process\Process($command); diff --git a/src/Process/ProcessInterface.php b/src/Process/ProcessInterface.php index b466461..12c32d9 100644 --- a/src/Process/ProcessInterface.php +++ b/src/Process/ProcessInterface.php @@ -6,5 +6,8 @@ interface ProcessInterface { + /** + * @param array $command + */ public function exec(array $command): string; } diff --git a/src/Version/Comparator.php b/src/Version/Comparator.php index c35ad8d..d3ea566 100644 --- a/src/Version/Comparator.php +++ b/src/Version/Comparator.php @@ -47,6 +47,7 @@ public static function compare(string $a, string $b): int * @param non-empty-string $requested * @param non-empty-string $installed */ + #[\Override] public function greaterThan(string $requested, string $installed): bool { return self::compare($this->parser->normalize($installed), $this->parser->normalize($requested)) >= 0; @@ -56,6 +57,7 @@ public function greaterThan(string $requested, string $installed): bool * @param non-empty-string $requested * @param non-empty-string $installed */ + #[\Override] public function lessThan(string $requested, string $installed): bool { return self::compare($this->parser->normalize($installed), $this->parser->normalize($requested)) <= 0; @@ -65,6 +67,7 @@ public function lessThan(string $requested, string $installed): bool * @param non-empty-string $requested * @param non-empty-string $installed */ + #[\Override] public function equal(string $requested, string $installed): bool { return self::compare($this->parser->normalize($installed), $this->parser->normalize($requested)) === 0; diff --git a/src/Version/Installed.php b/src/Version/Installed.php index 89d3645..8aa63e5 100644 --- a/src/Version/Installed.php +++ b/src/Version/Installed.php @@ -40,17 +40,18 @@ public function __construct( * * @throws RoadrunnerNotInstalledException */ + #[\Override] public function getInstalledVersion(): string { - if (!empty(self::$cachedVersion)) { + if (self::$cachedVersion !== null) { return self::$cachedVersion; } - if (!empty(self::$cachedVersion = $this->getVersionFromEnv())) { + if ((self::$cachedVersion = $this->getVersionFromEnv()) !== null) { return self::$cachedVersion; } - if (!empty(self::$cachedVersion = $this->getVersionFromConsoleCommand())) { + if ((self::$cachedVersion = $this->getVersionFromConsoleCommand()) !== null) { return self::$cachedVersion; } diff --git a/src/Version/Required.php b/src/Version/Required.php index cf0e7f4..2b6a862 100644 --- a/src/Version/Required.php +++ b/src/Version/Required.php @@ -26,6 +26,7 @@ public function __construct(?PackageInterface $package = null) /** * @return non-empty-string|null */ + #[\Override] public function getRequiredVersion(): ?string { if (self::$cachedVersion !== null) { diff --git a/src/VersionChecker.php b/src/VersionChecker.php index 66534df..86e2eee 100644 --- a/src/VersionChecker.php +++ b/src/VersionChecker.php @@ -31,7 +31,7 @@ public function __construct( } /** - * @param non-empty-string|null $version + * @param string|null $version Null or an empty string takes the version from the installed packages. * * @throws UnsupportedVersionException * @throws RoadrunnerNotInstalledException @@ -39,11 +39,11 @@ public function __construct( */ public function greaterThan(?string $version = null): void { - if (empty($version)) { + if ($version === null || $version === '') { $version = $this->requiredVersion->getRequiredVersion(); } - if (empty($version)) { + if ($version === null) { throw new RequiredVersionException( 'Unable to determine required RoadRunner version.' . ' Please specify the required version in the `$version` parameter.', @@ -108,9 +108,7 @@ public function equal(string $version): void */ private function getFormattedMessage(string $message, string $installedVersion, string $version): string { - \preg_match('/\bv?(\d+)\.(\d+)\.(\d+)\b/', $version, $matches); - - if (!empty($matches[0])) { + if (\preg_match('/\bv?(\d+)\.(\d+)\.(\d+)\b/', $version, $matches) === 1) { $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3]; }