Skip to content
Merged
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
6 changes: 1 addition & 5 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<referencedClass name="JetBrains\PhpStorm\ExpectedValues" />
</errorLevel>
</UndefinedAttributeClass>
<ClassMustBeFinal errorLevel="suppress" />
</issueHandlers>
</psalm>
8 changes: 7 additions & 1 deletion src/Composer/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<non-empty-string, non-empty-string>} $composerJson */
$composerJson = \json_decode(\file_get_contents($path . '/composer.json'), true);
$composerJson = \json_decode($content, true);

if (
isset($composerJson['require'][$packageName]) &&
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
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/Process/ProcessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

interface ProcessInterface
{
/**
* @param array<string> $command
*/
public function exec(array $command): string;
}
3 changes: 3 additions & 0 deletions src/Version/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Version/Installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/Version/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(?PackageInterface $package = null)
/**
* @return non-empty-string|null
*/
#[\Override]
public function getRequiredVersion(): ?string
{
if (self::$cachedVersion !== null) {
Expand Down
10 changes: 4 additions & 6 deletions src/VersionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ 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
* @throws RequiredVersionException
*/
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.',
Expand Down Expand Up @@ -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];
}

Expand Down
Loading