Skip to content

Commit df7da38

Browse files
committed
Note about incompatible turbo version
1 parent 01057cb commit df7da38

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎src/Command/AnalyseCommand.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
use PHPStan\Fixable\Patcher;
2626
use PHPStan\Internal\AgentDetector;
2727
use PHPStan\Internal\BytesHelper;
28+
use PHPStan\Internal\ComposerHelper;
2829
use PHPStan\Internal\DirectoryCreator;
2930
use PHPStan\Internal\DirectoryCreatorException;
3031
use PHPStan\ShouldNotHappenException;
32+
use PHPStan\Turbo\TurboExtensionEnabler;
3133
use Symfony\Component\Console\Command\Command;
3234
use Symfony\Component\Console\Input\InputArgument;
3335
use Symfony\Component\Console\Input\InputInterface;
@@ -319,6 +321,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
319321
));
320322
}
321323

324+
$incompatibleTurboVersion = TurboExtensionEnabler::getIncompatibleLoadedVersion();
325+
if ($incompatibleTurboVersion !== null) {
326+
$errorOutput->writeLineFormatted('<comment>Incompatible version of the phpstan_turbo extension</comment>');
327+
$errorOutput->writeLineFormatted(sprintf(
328+
'The loaded phpstan_turbo extension is version %s',
329+
$incompatibleTurboVersion,
330+
));
331+
$errorOutput->writeLineFormatted(sprintf(
332+
'but this PHPStan version expects version %s.',
333+
TurboExtensionEnabler::EXPECTED_EXTENSION_VERSION,
334+
));
335+
$errorOutput->writeLineFormatted('');
336+
$errorOutput->writeLineFormatted('The extension stays inactive and PHPStan runs slower than necessary.');
337+
$errorOutput->writeLineFormatted('');
338+
339+
$phpstanVersion = ComposerHelper::getPhpStanVersion();
340+
if ($phpstanVersion === ComposerHelper::UNKNOWN_VERSION) {
341+
$errorOutput->writeLineFormatted('Update the extension to the version appropriate for your PHPStan version.');
342+
} else {
343+
$errorOutput->writeLineFormatted(sprintf('Update the extension to the version appropriate for PHPStan %s.', $phpstanVersion));
344+
}
345+
$errorOutput->writeLineFormatted('');
346+
}
347+
322348
if ($pro) {
323349
if ($generateBaselineFile !== null) {
324350
$inceptionResult->getStdOutput()->getStyle()->error('You cannot pass the --generate-baseline option when running PHPStan Pro.');

‎src/Turbo/TurboExtensionEnabler.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ public static function isLoaded(): bool
6767
return extension_loaded('phpstan_turbo');
6868
}
6969

70+
/**
71+
* The version of the loaded extension when it does not pass the
72+
* enableIfLoaded() version gate. Null when the extension is not loaded,
73+
* deliberately disabled, or compatible.
74+
*/
75+
public static function getIncompatibleLoadedVersion(): ?string
76+
{
77+
if (!self::isLoaded()) {
78+
return null;
79+
}
80+
81+
if (getenv('PHPSTAN_TURBO') === '0') {
82+
return null;
83+
}
84+
85+
$version = phpversion('phpstan_turbo');
86+
if ($version === self::EXPECTED_EXTENSION_VERSION) {
87+
return null;
88+
}
89+
90+
return $version === false ? 'unknown' : $version;
91+
}
92+
7093
/**
7194
* Whether enableIfLoaded() actually activated the extension — the stubs
7295
* shadow the PHP implementations only in that case.

0 commit comments

Comments
 (0)