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
9 changes: 1 addition & 8 deletions bin/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,9 @@ use Symfony\Component\Console\Helper\ProgressBar;

$devOrPharLoader->register(true);

$version = 'Version unknown';
try {
$version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion() ?: $version;
} catch (\OutOfBoundsException $e) {

}

$application = new \Symfony\Component\Console\Application(
'PHPStan - PHP Static Analysis Tool',
$version
ComposerHelper::getPhpStanVersion()
);
$application->setDefaultCommand('analyse');
ProgressBar::setFormatDefinition('file_download', ' [%bar%] %percent:3s%% %fileSize%');
Expand Down
7 changes: 7 additions & 0 deletions compiler/build/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ function (string $filePath, string $prefix, string $content): string {

return str_replace(sprintf('%s\\Composer\\Autoload\\ClassLoader', $prefix), 'Composer\\Autoload\\ClassLoader', $content);
},
function (string $filePath, string $prefix, string $content): string {
if ($filePath !== 'src/Internal/ComposerHelper.php') {
return $content;
}

return str_replace(sprintf('%s\\Composer\\InstalledVersions', $prefix), 'Composer\\InstalledVersions', $content);
},
function (string $filePath, string $prefix, string $content): string {
if ($filePath !== 'vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php') {
return $content;
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"require": {
"php": "^8.0",
"composer-runtime-api": "^2.0",
"clue/block-react": "^1.4",
"clue/ndjson-react": "^1.0",
"composer/ca-bundle": "^1.2",
"composer/xdebug-handler": "^3.0.3",
"hoa/compiler": "3.17.08.08",
"hoa/exception": "^1.0",
"hoa/regex": "1.17.01.13",
"jean85/pretty-package-versions": "^1.0.3",
"jetbrains/phpstorm-stubs": "dev-master#01006d9854679672fc8b85c6d5063ea6f25226ac",
"nette/bootstrap": "^3.0",
"nette/di": "^3.0.11",
Expand Down Expand Up @@ -68,7 +68,6 @@
"platform-check": false,
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"vaimo/composer-patches": true
}
},
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace PHPStan\Analyser\ResultCache;

use Jean85\PrettyVersions;
use Nette\DI\Definitions\Statement;
use Nette\Neon\Neon;
use OutOfBoundsException;
use PHPStan\Analyser\AnalyserResult;
use PHPStan\Analyser\Error;
use PHPStan\Collectors\CollectedData;
Expand Down Expand Up @@ -731,7 +729,7 @@ private function getMeta(array $allAnalysedFiles, ?array $projectConfigArray): a

return [
'cacheVersion' => self::CACHE_VERSION,
'phpstanVersion' => $this->getPhpStanVersion(),
'phpstanVersion' => ComposerHelper::getPhpStanVersion(),
'phpVersion' => PHP_VERSION_ID,
'projectConfig' => $projectConfigArray,
'analysedPaths' => $this->analysedPaths,
Expand Down Expand Up @@ -805,15 +803,6 @@ private function getExecutedFileHashes(): array
return $hashes;
}

private function getPhpStanVersion(): string
{
try {
return PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
} catch (OutOfBoundsException) {
return 'Version unknown';
}
}

/**
* @return array<string, string>
*/
Expand Down
14 changes: 2 additions & 12 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use Jean85\PrettyVersions;
use Nette\Utils\Json;
use OutOfBoundsException;
use Phar;
use PHPStan\Analyser\AnalyserResult;
use PHPStan\Analyser\Error;
Expand All @@ -22,6 +20,7 @@
use PHPStan\File\FileMonitorResult;
use PHPStan\File\FileReader;
use PHPStan\File\FileWriter;
use PHPStan\Internal\ComposerHelper;
use PHPStan\Parallel\Scheduler;
use PHPStan\Process\CpuCoreCounter;
use PHPStan\Process\ProcessCanceledException;
Expand Down Expand Up @@ -146,7 +145,7 @@ public function log(string $message): void
'analysedPaths' => $this->analysedPaths,
'projectConfigFile' => $projectConfigFile,
'filesCount' => $filesCount,
'phpstanVersion' => $this->getPhpstanVersion(),
'phpstanVersion' => ComposerHelper::getPhpStanVersion(),
]]);
$decoder->on('data', function (array $data) use (
$loop,
Expand Down Expand Up @@ -557,15 +556,6 @@ private function reanalyseAfterFileChanges(
return $this->processInProgress->then(static fn (string $output): array => Json::decode($output, Json::FORCE_ARRAY));
}

private function getPhpstanVersion(): string
{
try {
return PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
} catch (OutOfBoundsException) {
return 'Version unknown';
}
}

private function isDockerRunning(): bool
{
if (!is_file('/proc/1/cgroup')) {
Expand Down
15 changes: 15 additions & 0 deletions src/Internal/ComposerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Internal;

use Composer\InstalledVersions;
use Nette\Utils\Json;
use Nette\Utils\JsonException;
use PHPStan\File\CouldNotReadFileException;
Expand All @@ -10,6 +11,8 @@
use function getenv;
use function is_file;
use function is_string;
use function preg_match;
use function substr;
use function trim;

final class ComposerHelper
Expand Down Expand Up @@ -52,4 +55,16 @@ public static function getVendorDirFromComposerConfig(string $root, array $compo
return $root . '/' . trim($vendorDirectory, '/');
}

public static function getPhpStanVersion(): string
{
$rootPackage = InstalledVersions::getRootPackage();

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 $rootPackage['pretty_version'] . '@' . substr((string) $rootPackage['reference'], 0, 7);
}

}