|
2 | 2 |
|
3 | 3 | namespace PHPStan\Command;
|
4 | 4 |
|
| 5 | +use Composer\Semver\Semver; |
5 | 6 | use Composer\XdebugHandler\XdebugHandler;
|
6 | 7 | use Nette\DI\Helpers;
|
7 | 8 | use Nette\DI\InvalidConfigurationException;
|
|
23 | 24 | use PHPStan\File\FileExcluder;
|
24 | 25 | use PHPStan\File\FileFinder;
|
25 | 26 | use PHPStan\File\FileHelper;
|
| 27 | +use PHPStan\File\SimpleRelativePathHelper; |
| 28 | +use PHPStan\Internal\ComposerHelper; |
26 | 29 | use PHPStan\Internal\DirectoryCreator;
|
27 | 30 | use PHPStan\Internal\DirectoryCreatorException;
|
28 | 31 | use PHPStan\PhpDoc\StubFilesProvider;
|
@@ -279,6 +282,43 @@ public static function begin(
|
279 | 282 | $additionalConfigFiles[] = $includedFilePath;
|
280 | 283 | }
|
281 | 284 | }
|
| 285 | + |
| 286 | + if ( |
| 287 | + count($additionalConfigFiles) > 0 |
| 288 | + && $generatedConfigReflection->hasConstant('PHPSTAN_VERSION_CONSTRAINT') |
| 289 | + ) { |
| 290 | + $generatedConfigPhpStanVersionConstraint = $generatedConfigReflection->getConstant('PHPSTAN_VERSION_CONSTRAINT'); |
| 291 | + if ($generatedConfigPhpStanVersionConstraint !== null) { |
| 292 | + $phpstanSemverVersion = ComposerHelper::getPhpStanVersion(); |
| 293 | + if ( |
| 294 | + $phpstanSemverVersion !== ComposerHelper::UNKNOWN_VERSION |
| 295 | + && !str_contains($phpstanSemverVersion, '@') |
| 296 | + && !Semver::satisfies($phpstanSemverVersion, $generatedConfigPhpStanVersionConstraint) |
| 297 | + ) { |
| 298 | + $errorOutput->writeLineFormatted('<error>Running PHPStan with incompatible extensions</error>'); |
| 299 | + $errorOutput->writeLineFormatted('You\'re running PHPStan from a different Composer project'); |
| 300 | + $errorOutput->writeLineFormatted('than the one where you installed extensions.'); |
| 301 | + $errorOutput->writeLineFormatted(''); |
| 302 | + $errorOutput->writeLineFormatted(sprintf('Your PHPStan version is: <fg=red>%s</>', $phpstanSemverVersion)); |
| 303 | + $errorOutput->writeLineFormatted(sprintf('Installed PHPStan extensions support: %s', $generatedConfigPhpStanVersionConstraint)); |
| 304 | + |
| 305 | + $errorOutput->writeLineFormatted(''); |
| 306 | + if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) { |
| 307 | + $mainScript = $_SERVER['argv'][0]; |
| 308 | + $errorOutput->writeLineFormatted(sprintf('PHPStan is running from: %s', $currentWorkingDirectoryFileHelper->absolutizePath(dirname($mainScript)))); |
| 309 | + } |
| 310 | + |
| 311 | + $errorOutput->writeLineFormatted(sprintf('Extensions were installed in: %s', dirname($generatedConfigDirectory, 3))); |
| 312 | + $errorOutput->writeLineFormatted(''); |
| 313 | + |
| 314 | + $simpleRelativePathHelper = new SimpleRelativePathHelper($currentWorkingDirectory); |
| 315 | + $errorOutput->writeLineFormatted(sprintf('Run PHPStan with <fg=green>%s</> to fix this problem.', $simpleRelativePathHelper->getRelativePath(dirname($generatedConfigDirectory, 3) . '/bin/phpstan'))); |
| 316 | + |
| 317 | + $errorOutput->writeLineFormatted(''); |
| 318 | + throw new InceptionNotSuccessfulException(); |
| 319 | + } |
| 320 | + } |
| 321 | + } |
282 | 322 | }
|
283 | 323 |
|
284 | 324 | if (
|
|
0 commit comments