Skip to content

Commit 12cebb3

Browse files
committed
Fix PHAR scoping of trigger_deprecation(), remove stale scoper patchers
- Expose trigger_deprecation() so Symfony's unqualified calls reach it (they called a nonexistent function unless the analysed project defined it) - Exclude Composer ClassLoader and InstalledVersions via exclude-classes instead of a per-file patcher (also fixes nette/bootstrap) - Apply the use PhpParser; fix to all files (fixes nette/php-generator) - Remove patchers that no longer change anything Amp-Thread-ID: https://ampcode.com/threads/T-01a179f8-e6bb-7020-8500-cfc35a10dfc5
1 parent eeee567 commit 12cebb3

1 file changed

Lines changed: 6 additions & 54 deletions

File tree

‎compiler/build/scoper.inc.php‎

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
'exclude-files' => $stubs,
4848
'php-version' => '7.4',
4949
'patchers' => [
50-
function (string $filePath, string $prefix, string $content): string {
51-
if ($filePath !== 'vendor/nette/di/src/DI/Compiler.php') {
52-
return $content;
53-
}
54-
return str_replace('|Nette\\DI\\Statement', sprintf('|\\%s\\Nette\\DI\\Statement', $prefix), $content);
55-
},
5650
function (string $filePath, string $prefix, string $content): string {
5751
if ($filePath !== 'vendor/nette/di/src/DI/Extensions/DefinitionSchema.php') {
5852
return $content;
@@ -135,26 +129,6 @@ function (string $filePath, string $prefix, string $content): string {
135129

136130
return \Nette\Neon\Neon::encode($updatedNeon, \Nette\Neon\Neon::BLOCK);
137131
},
138-
function (string $filePath, string $prefix, string $content): string {
139-
if (!in_array($filePath, [
140-
'bin/phpstan',
141-
'src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php',
142-
'src/Testing/TestCaseSourceLocatorFactory.php',
143-
'src/Testing/PHPStanTestCase.php',
144-
'vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/ComposerSourceLocator.php',
145-
], true)) {
146-
return $content;
147-
}
148-
149-
return str_replace(sprintf('%s\\Composer\\Autoload\\ClassLoader', $prefix), 'Composer\\Autoload\\ClassLoader', $content);
150-
},
151-
function (string $filePath, string $prefix, string $content): string {
152-
if ($filePath !== 'src/Internal/ComposerHelper.php') {
153-
return $content;
154-
}
155-
156-
return str_replace(sprintf('%s\\Composer\\InstalledVersions', $prefix), 'Composer\\InstalledVersions', $content);
157-
},
158132
function (string $filePath, string $prefix, string $content): string {
159133
if ($filePath !== 'vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php') {
160134
return $content;
@@ -178,39 +152,12 @@ function (string $filePath, string $prefix, string $content): string {
178152
return $content;
179153
}
180154

181-
return str_replace('Core/Core_d.php', 'Core/Core_d.stub', $content);
182-
},
183-
function (string $filePath, string $prefix, string $content): string {
184-
if ($filePath !== 'vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php') {
185-
return $content;
186-
}
187-
188155
return str_replace(sprintf('\'%s\\JetBrains\\', $prefix), '\'JetBrains\\', $content);
189156
},
190157
function (string $filePath, string $prefix, string $content): string {
191-
if (!str_starts_with($filePath, 'vendor/nikic/php-parser/lib')) {
192-
return $content;
193-
}
194-
158+
// php-scoper prefixes `use PhpParser;` even though the namespace is excluded (php-parser itself, nette/php-generator)
195159
return str_replace(sprintf('use %s\\PhpParser;', $prefix), 'use PhpParser;', $content);
196160
},
197-
function (string $filePath, string $prefix, string $content): string {
198-
if (!str_starts_with($filePath, 'vendor/nikic/php-parser/lib')) {
199-
return $content;
200-
}
201-
202-
return str_replace([
203-
sprintf('\\%s', $prefix),
204-
sprintf('\\\\%s', $prefix),
205-
], '', $content);
206-
},
207-
function (string $filePath, string $prefix, string $content): string {
208-
if (!str_starts_with($filePath, 'vendor/ondrejmirtes/better-reflection')) {
209-
return $content;
210-
}
211-
212-
return str_replace(sprintf('%s\\PropertyHookType', $prefix), 'PropertyHookType', $content);
213-
},
214161
function (string $filePath, string $prefix, string $content) use ($namespaces): string {
215162
if (strpos($filePath, 'src/') !== 0) {
216163
return $content;
@@ -228,5 +175,10 @@ function (string $filePath, string $prefix, string $content) use ($namespaces):
228175
],
229176
'exclude-namespaces' => $namespaces['excluded'],
230177
'expose-global-functions' => false,
178+
// shared with the analysed project's Composer autoloader
179+
'exclude-classes' => ['Composer\\Autoload\\ClassLoader', 'Composer\\InstalledVersions'],
180+
// symfony/deprecation-contracts declares it in the global namespace and Symfony calls it unqualified
181+
// from its own namespaces - without a global alias those calls resolve to a function that does not exist
182+
'expose-functions' => ['trigger_deprecation'],
231183
'expose-global-classes' => false,
232184
];

0 commit comments

Comments
 (0)