diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml
index 30dcb45..518b472 100644
--- a/.github/workflows/cs.yml
+++ b/.github/workflows/cs.yml
@@ -1,14 +1,12 @@
on:
- pull_request: null
push:
branches:
- - 1.x
+ - '*'
-name: coding-standards
+name: Fix Code Style
jobs:
- psalm:
- uses: spiral/gh-actions/.github/workflows/cs.yml@master
- with:
- os: >-
- ['ubuntu-latest']
+ cs-fix:
+ permissions:
+ contents: write
+ uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master
diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index 5a77d0b..ac19e88 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -13,6 +13,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.0', '8.1', '8.2', '8.3']
+ ['8.1', '8.2', '8.3', '8.4']
stability: >-
['prefer-lowest', 'prefer-stable']
diff --git a/.gitignore b/.gitignore
index 2fe23be..3963707 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ docs
vendor
node_modules
.php-cs-fixer.cache
+/runtime
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 9b1d84a..4b418a0 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -2,19 +2,16 @@
declare(strict_types=1);
-if (!file_exists(__DIR__.'/src')) {
- exit(0);
-}
+use Spiral\CodeStyle\Builder;
-return (new PhpCsFixer\Config())
- ->setRules([
- '@PSR12' => true,
- 'ternary_operator_spaces' => false,
- ])
- ->setRiskyAllowed(true)
- ->setFinder(
- (new PhpCsFixer\Finder())
- ->in(__DIR__.'/src')
- ->append([__FILE__])
- )
- ->setCacheFile('.php-cs-fixer.cache');
+require_once 'vendor/autoload.php';
+
+
+return Builder::create()
+ ->include(__DIR__ . '/src')
+ ->include(__FILE__)
+ ->build()->setRules([
+ 'ordered_imports' => ['sort_algorithm' => 'alpha'],
+ 'fully_qualified_strict_types' => true,
+ 'no_unused_imports' => true,
+ ]);
diff --git a/README.md b/README.md
index dba2cfd..e3a8eef 100644
--- a/README.md
+++ b/README.md
@@ -8,12 +8,6 @@
[](https://packagist.org/roadrunner-php/version-checker/phpunit)
-## Requirements
-
-Make sure that your server is configured with following PHP version and extensions:
-
-- PHP 8.0+
-
## Installation
You can install the package via composer:
diff --git a/composer.json b/composer.json
index 22dd13c..b5e96d9 100644
--- a/composer.json
+++ b/composer.json
@@ -9,15 +9,16 @@
"homepage": "https://github.com/roadrunner-php/version-checker",
"license": "MIT",
"require": {
- "php": "^8.0",
- "symfony/process": "^5.4 || ^6.0 || ^7.0",
+ "php": ">=8.1",
"composer-runtime-api": "^2.0",
- "composer/semver": "^3.3"
+ "composer/semver": "^3.3",
+ "symfony/process": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
+ "phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^9.6 || ^10.0",
- "vimeo/psalm": "^5.9",
- "friendsofphp/php-cs-fixer": "^3.8"
+ "spiral/code-style": "^2.2",
+ "vimeo/psalm": "^6.0"
},
"autoload": {
"psr-4": {
@@ -32,7 +33,8 @@
"scripts": {
"test": "vendor/bin/phpunit",
"psalm": "vendor/bin/psalm --config=psalm.xml ./src",
- "cs": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -vvv --dry-run --using-cache=no"
+ "cs:diff": "php-cs-fixer fix --dry-run -v --diff",
+ "cs:fix": "php-cs-fixer fix -v"
},
"config": {
"sort-packages": true
diff --git a/psalm.xml b/psalm.xml
index 967944d..dab13ea 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -13,11 +13,4 @@
-
-
-
-
-
-
-
diff --git a/src/Composer/Package.php b/src/Composer/Package.php
index f2824c8..93a45a7 100644
--- a/src/Composer/Package.php
+++ b/src/Composer/Package.php
@@ -11,8 +11,12 @@ final class Package implements PackageInterface
{
/**
* @param non-empty-string $packageName
- * @return non-empty-string[]
+ *
+ * @return string[]
+ *
+ * @psalm-return list
*/
+ #[\Override]
public function getRequiredVersions(string $packageName): array
{
$versions = [];
@@ -20,13 +24,21 @@ public function getRequiredVersions(string $packageName): array
$path = InstalledVersions::getInstallPath($package);
if ($path !== null && \file_exists($path . '/composer.json')) {
/** @var array{require?: array} $composerJson */
- $composerJson = \json_decode(\file_get_contents($path . '/composer.json'), true);
+ $fileContent = \file_get_contents($path . '/composer.json');
+ /** @var array|null $composerJson */
+ $composerJson = $fileContent === false ? null : \json_decode($fileContent, true);
+
+ if (isset($composerJson['require'][$packageName])) {
+ /** @var mixed $rawPackage */
+ $rawPackage = $composerJson['require'][$packageName];
+
+ if (is_string($rawPackage) && strlen($rawPackage) > 0) {
+ assert($rawPackage !== '');
- if (
- isset($composerJson['require'][$packageName]) &&
- $this->isSupportedVersion($composerJson['require'][$packageName])
- ) {
- $versions[] = $this->getMinVersion($composerJson['require'][$packageName]);
+ if ($this->isSupportedVersion($rawPackage)) {
+ $versions[] = $this->getMinVersion($rawPackage);
+ }
+ }
}
}
}
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/Exception/RequiredVersionException.php b/src/Exception/RequiredVersionException.php
index d741df7..9346254 100644
--- a/src/Exception/RequiredVersionException.php
+++ b/src/Exception/RequiredVersionException.php
@@ -4,6 +4,4 @@
namespace RoadRunner\VersionChecker\Exception;
-final class RequiredVersionException extends VersionCheckerException
-{
-}
+final class RequiredVersionException extends VersionCheckerException {}
diff --git a/src/Exception/RoadrunnerNotInstalledException.php b/src/Exception/RoadrunnerNotInstalledException.php
index 24dfdd0..1d947c6 100644
--- a/src/Exception/RoadrunnerNotInstalledException.php
+++ b/src/Exception/RoadrunnerNotInstalledException.php
@@ -4,6 +4,4 @@
namespace RoadRunner\VersionChecker\Exception;
-final class RoadrunnerNotInstalledException extends VersionCheckerException
-{
-}
+final class RoadrunnerNotInstalledException extends VersionCheckerException {}
diff --git a/src/Exception/VersionCheckerException.php b/src/Exception/VersionCheckerException.php
index 9cccac3..9b0a47e 100644
--- a/src/Exception/VersionCheckerException.php
+++ b/src/Exception/VersionCheckerException.php
@@ -4,6 +4,4 @@
namespace RoadRunner\VersionChecker\Exception;
-abstract class VersionCheckerException extends \Exception
-{
-}
+abstract class VersionCheckerException extends \Exception {}
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/Version/Comparator.php b/src/Version/Comparator.php
index a3e6a13..f40387b 100644
--- a/src/Version/Comparator.php
+++ b/src/Version/Comparator.php
@@ -20,6 +20,7 @@ public function __construct(?VersionParser $parser = null)
* @param non-empty-string $requested
* @param non-empty-string $installed
*/
+ #[\Override]
public function greaterThan(string $requested, string $installed): bool
{
return SemverComparator::greaterThanOrEqualTo(
@@ -32,6 +33,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 SemverComparator::lessThanOrEqualTo(
@@ -44,6 +46,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 SemverComparator::equalTo(
diff --git a/src/Version/Installed.php b/src/Version/Installed.php
index 89d3645..595da77 100644
--- a/src/Version/Installed.php
+++ b/src/Version/Installed.php
@@ -40,27 +40,30 @@ 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())) {
- return self::$cachedVersion;
+ $version = $this->getVersionFromEnv();
+ if ($version != null) {
+ return self::$cachedVersion = $version;
}
- if (!empty(self::$cachedVersion = $this->getVersionFromConsoleCommand())) {
- return self::$cachedVersion;
+ $version = $this->getVersionFromConsoleCommand();
+ if ($version != null) {
+ return self::$cachedVersion = $version;
}
throw new RoadrunnerNotInstalledException('Unable to determine RoadRunner version.');
}
/**
- * @return non-empty-string|null
+ * @return null|string
*/
- private function getVersionFromEnv(): ?string
+ private function getVersionFromEnv(): string|null
{
/** @var string|null $version */
$version = $this->environment->get(self::ENV_VARIABLE);
@@ -73,10 +76,11 @@ private function getVersionFromEnv(): ?string
}
/**
- * @return non-empty-string|null
+ * @return null|string
+ *
* @throws RoadrunnerNotInstalledException
*/
- private function getVersionFromConsoleCommand(): ?string
+ private function getVersionFromConsoleCommand(): string|null
{
try {
$output = $this->process->exec([$this->executablePath, '--version']);
diff --git a/src/Version/Required.php b/src/Version/Required.php
index 6827eef..2752158 100644
--- a/src/Version/Required.php
+++ b/src/Version/Required.php
@@ -27,6 +27,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..ab7e448 100644
--- a/src/VersionChecker.php
+++ b/src/VersionChecker.php
@@ -39,11 +39,11 @@ public function __construct(
*/
public function greaterThan(?string $version = null): void
{
- if (empty($version)) {
+ if ($version == null) {
$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.',
@@ -110,11 +110,10 @@ private function getFormattedMessage(string $message, string $installedVersion,
{
\preg_match('/\bv?(\d+)\.(\d+)\.(\d+)\b/', $version, $matches);
- if (!empty($matches[0])) {
+ if (isset($matches[0]) && $matches[0] != null) {
$version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
}
- /** @var non-empty-string $msg */
$msg = \sprintf($message, $installedVersion, $version);
return $msg;