Skip to content

Commit

Permalink
Do not use Composer\InstalledVersions to parse PHPStan version
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 6, 2022
1 parent fd94186 commit acbb55b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Internal/ComposerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPStan\Internal;

use Composer\InstalledVersions;
use Nette\Utils\Json;
use Nette\Utils\JsonException;
use PHPStan\File\CouldNotReadFileException;
Expand All @@ -18,6 +17,8 @@
final class ComposerHelper
{

private static ?string $phpstanVersion = null;

/** @return array<string, mixed> */
public static function getComposerConfig(string $root): ?array
{
Expand Down Expand Up @@ -57,14 +58,22 @@ public static function getVendorDirFromComposerConfig(string $root, array $compo

public static function getPhpStanVersion(): string
{
$rootPackage = InstalledVersions::getRootPackage();
if (self::$phpstanVersion !== null) {
return self::$phpstanVersion;
}

$installed = require __DIR__ . '/../../vendor/composer/installed.php';
$rootPackage = $installed['root'] ?? null;
if ($rootPackage === null) {
return self::$phpstanVersion = 'Unknown version';
}

if (preg_match('/[^v\d.]/', $rootPackage['pretty_version']) === 0) {
// Handles tagged versions, see https://github.com/Jean85/pretty-package-versions/blob/2.0.5/src/Version.php#L31
return $rootPackage['pretty_version'];
return self::$phpstanVersion = $rootPackage['pretty_version'];
}

return $rootPackage['pretty_version'] . '@' . substr((string) $rootPackage['reference'], 0, 7);
return self::$phpstanVersion = $rootPackage['pretty_version'] . '@' . substr((string) $rootPackage['reference'], 0, 7);
}

}

0 comments on commit acbb55b

Please sign in to comment.