|
2 | 2 |
|
3 | 3 | namespace PHPStan\Internal; |
4 | 4 |
|
5 | | -use Composer\InstalledVersions; |
6 | 5 | use Nette\Utils\Json; |
7 | 6 | use Nette\Utils\JsonException; |
8 | 7 | use PHPStan\File\CouldNotReadFileException; |
|
18 | 17 | final class ComposerHelper |
19 | 18 | { |
20 | 19 |
|
| 20 | + private static ?string $phpstanVersion = null; |
| 21 | + |
21 | 22 | /** @return array<string, mixed> */ |
22 | 23 | public static function getComposerConfig(string $root): ?array |
23 | 24 | { |
@@ -57,14 +58,22 @@ public static function getVendorDirFromComposerConfig(string $root, array $compo |
57 | 58 |
|
58 | 59 | public static function getPhpStanVersion(): string |
59 | 60 | { |
60 | | - $rootPackage = InstalledVersions::getRootPackage(); |
| 61 | + if (self::$phpstanVersion !== null) { |
| 62 | + return self::$phpstanVersion; |
| 63 | + } |
| 64 | + |
| 65 | + $installed = require __DIR__ . '/../../vendor/composer/installed.php'; |
| 66 | + $rootPackage = $installed['root'] ?? null; |
| 67 | + if ($rootPackage === null) { |
| 68 | + return self::$phpstanVersion = 'Unknown version'; |
| 69 | + } |
61 | 70 |
|
62 | 71 | if (preg_match('/[^v\d.]/', $rootPackage['pretty_version']) === 0) { |
63 | 72 | // Handles tagged versions, see https://github.com/Jean85/pretty-package-versions/blob/2.0.5/src/Version.php#L31 |
64 | | - return $rootPackage['pretty_version']; |
| 73 | + return self::$phpstanVersion = $rootPackage['pretty_version']; |
65 | 74 | } |
66 | 75 |
|
67 | | - return $rootPackage['pretty_version'] . '@' . substr((string) $rootPackage['reference'], 0, 7); |
| 76 | + return self::$phpstanVersion = $rootPackage['pretty_version'] . '@' . substr((string) $rootPackage['reference'], 0, 7); |
68 | 77 | } |
69 | 78 |
|
70 | 79 | } |
0 commit comments