Skip to content

Commit 6a460c5

Browse files
committed
Format PHP version without PhpVersion in RestartExtensionRegistry
The registry runs in bin/phpstan before the autoloader is registered, so PhpVersion could not be loaded when Tideways was stripped on an affected PHP version. Closes phpstan/phpstan#15913 Amp-Thread-ID: https://ampcode.com/threads/T-01a23742-84e5-7230-805a-47cef0e7c826
1 parent 7790471 commit 6a460c5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/Process/Restart/RestartExtensionRegistry.php‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Process\Restart;
44

5-
use PHPStan\Php\PhpVersion;
65
use PHPStan\Turbo\TurboExtensionSelector;
76
use function array_key_exists;
87
use function explode;
@@ -12,6 +11,7 @@
1211
use function getenv;
1312
use function in_array;
1413
use function ini_get;
14+
use function intdiv;
1515
use function phpversion;
1616
use function sprintf;
1717
use function str_replace;
@@ -217,7 +217,7 @@ public static function collectReasonsFor(
217217
) {
218218
$reasons[] = new RestartReason(
219219
'tideways',
220-
sprintf('crashes the turbo extension on PHP %s, %s', (new PhpVersion($phpVersionId))->getVersionString(), self::TIDEWAYS_FIX_DESCRIPTION),
220+
sprintf('crashes the turbo extension on PHP %s, %s', self::describePhpVersion($phpVersionId), self::TIDEWAYS_FIX_DESCRIPTION),
221221
strippedExtensions: ['tideways'],
222222
);
223223
}
@@ -279,7 +279,7 @@ public static function describeDetectedExtensions(): array
279279
? 'tideways %s (unloaded wherever the turbo extension runs: crashes it on PHP %s, ' . self::TIDEWAYS_FIX_DESCRIPTION . ')'
280280
: 'tideways %s (kept next to the turbo extension: PHP %s is not affected by the crash)',
281281
self::describeVersion('tideways'),
282-
(new PhpVersion(PHP_VERSION_ID))->getVersionString(),
282+
self::describePhpVersion(PHP_VERSION_ID),
283283
);
284284
}
285285

@@ -356,6 +356,15 @@ private static function isAffectedByTidewaysCrash(int $phpVersionId): bool
356356
|| ($phpVersionId >= 80400 && $phpVersionId < 80403);
357357
}
358358

359+
/**
360+
* Formatted here rather than by PhpVersion: this class runs in bin/phpstan
361+
* before the autoloader is registered.
362+
*/
363+
private static function describePhpVersion(int $phpVersionId): string
364+
{
365+
return sprintf('%d.%d.%d', intdiv($phpVersionId, 10000), intdiv($phpVersionId, 100) % 100, $phpVersionId % 100);
366+
}
367+
359368
private static function isForkCapable(): bool
360369
{
361370
return function_exists('pcntl_fork')

0 commit comments

Comments
 (0)