Skip to content

Commit 184d34e

Browse files
SanderMullerclaude
authored andcommitted
Share the runtime checks of findExtension() and isMissingNextToPhar()
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent e947164 commit 184d34e

1 file changed

Lines changed: 35 additions & 29 deletions

File tree

‎src/Turbo/TurboExtensionSelector.php‎

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,15 @@ public static function findExtensionForWorkers(): ?string
8282
*/
8383
public static function isMissingNextToPhar(): bool
8484
{
85-
// no binary is built for these runtimes, so installing PHPStan with
86-
// Composer would not bring the extension either (see findExtension())
87-
if (PHP_VERSION_ID < self::MINIMUM_PHP_VERSION_ID || (bool) PHP_DEBUG) {
85+
$platformDirectory = self::getPlatformDirectoryNextToPhar();
86+
if ($platformDirectory === null) {
8887
return false;
8988
}
9089
if (TurboExtensionEnabler::isLoaded()) {
9190
return false;
9291
}
9392

94-
$pharPath = Phar::running(false);
95-
if ($pharPath === '') {
96-
return false;
97-
}
98-
if (self::resolvePlatformDirectory(PHP_OS_FAMILY, php_uname('m'), self::isMusl()) === null) {
99-
return false;
100-
}
101-
102-
return !is_dir(dirname($pharPath) . '/turbo-ext');
93+
return !is_dir(dirname($platformDirectory));
10394
}
10495

10596
/**
@@ -108,27 +99,14 @@ public static function isMissingNextToPhar(): bool
10899
*/
109100
public static function findExtension(): ?string
110101
{
111-
if (PHP_VERSION_ID < self::MINIMUM_PHP_VERSION_ID) {
112-
return null;
113-
}
114-
if ((bool) PHP_DEBUG) {
115-
return null;
116-
}
117-
118-
$pharPath = Phar::running(false);
119-
if ($pharPath === '') {
120-
return null;
121-
}
122-
123-
$platform = self::resolvePlatformDirectory(PHP_OS_FAMILY, php_uname('m'), self::isMusl());
124-
if ($platform === null) {
102+
$platformDirectory = self::getPlatformDirectoryNextToPhar();
103+
if ($platformDirectory === null) {
125104
return null;
126105
}
127106

128107
$file = sprintf(
129-
'%s/turbo-ext/%s/phpstan_turbo-%d.%d%s.%s',
130-
dirname($pharPath),
131-
$platform,
108+
'%s/phpstan_turbo-%d.%d%s.%s',
109+
$platformDirectory,
132110
PHP_MAJOR_VERSION,
133111
PHP_MINOR_VERSION,
134112
(bool) PHP_ZTS ? '-zts' : '',
@@ -147,6 +125,34 @@ public static function findExtension(): ?string
147125
return $file;
148126
}
149127

128+
/**
129+
* The directory of turbo-ext/ next to the running phar that holds the
130+
* binaries for this platform, whether it exists or not. Null when no
131+
* binary is built for this runtime: PHP older than the minimum, a debug
132+
* build, a run from source, or a platform without binaries.
133+
*/
134+
private static function getPlatformDirectoryNextToPhar(): ?string
135+
{
136+
if (PHP_VERSION_ID < self::MINIMUM_PHP_VERSION_ID) {
137+
return null;
138+
}
139+
if ((bool) PHP_DEBUG) {
140+
return null;
141+
}
142+
143+
$pharPath = Phar::running(false);
144+
if ($pharPath === '') {
145+
return null;
146+
}
147+
148+
$platform = self::resolvePlatformDirectory(PHP_OS_FAMILY, php_uname('m'), self::isMusl());
149+
if ($platform === null) {
150+
return null;
151+
}
152+
153+
return sprintf('%s/turbo-ext/%s', dirname($pharPath), $platform);
154+
}
155+
150156
/**
151157
* The shared core the extension binary loads, in the same directory.
152158
*/

0 commit comments

Comments
 (0)