Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ docs
vendor
node_modules
.php-cs-fixer.cache
/runtime
27 changes: 12 additions & 15 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]);
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
[![Total Downloads](https://poser.pugx.org/roadrunner-php/version-checker/downloads)](https://packagist.org/roadrunner-php/version-checker/phpunit)
<a href="https://discord.gg/8bZsjYhVVk"><img src="https://img.shields.io/badge/discord-chat-magenta.svg"></a>

## 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:
Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,4 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<referencedClass name="JetBrains\PhpStorm\ExpectedValues" />
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>
26 changes: 19 additions & 7 deletions src/Composer/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@ final class Package implements PackageInterface
{
/**
* @param non-empty-string $packageName
* @return non-empty-string[]
*
* @return string[]
*
* @psalm-return list<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')) {
/** @var array{require?: array<non-empty-string, non-empty-string>} $composerJson */
$composerJson = \json_decode(\file_get_contents($path . '/composer.json'), true);
$fileContent = \file_get_contents($path . '/composer.json');
/** @var array<string, mixed>|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);
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Environment/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/RequiredVersionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace RoadRunner\VersionChecker\Exception;

final class RequiredVersionException extends VersionCheckerException
{
}
final class RequiredVersionException extends VersionCheckerException {}
4 changes: 1 addition & 3 deletions src/Exception/RoadrunnerNotInstalledException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace RoadRunner\VersionChecker\Exception;

final class RoadrunnerNotInstalledException extends VersionCheckerException
{
}
final class RoadrunnerNotInstalledException extends VersionCheckerException {}
4 changes: 1 addition & 3 deletions src/Exception/VersionCheckerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace RoadRunner\VersionChecker\Exception;

abstract class VersionCheckerException extends \Exception
{
}
abstract class VersionCheckerException extends \Exception {}
1 change: 1 addition & 0 deletions src/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

final class Process implements ProcessInterface
{
#[\Override]
public function exec(array $command): string
{
$process = new \Symfony\Component\Process\Process($command);
Expand Down
3 changes: 3 additions & 0 deletions src/Version/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
22 changes: 13 additions & 9 deletions src/Version/Installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions src/Version/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(?PackageInterface $package = null)
/**
* @return non-empty-string|null
*/
#[\Override]
public function getRequiredVersion(): ?string
{
if (self::$cachedVersion !== null) {
Expand Down
7 changes: 3 additions & 4 deletions src/VersionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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;
Expand Down
Loading