diff --git a/scoper.inc.php b/scoper.inc.php index 058a947a..f8180202 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -46,56 +46,17 @@ return $files; })(); -$polyfillsBootstraps = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - Finder::create() - ->files() - ->in(__DIR__.'/vendor/symfony/polyfill-*') - ->name('bootstrap*.php'), - false, - ), -); - -$polyfillsStubs = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - Finder::create() - ->files() - ->in(__DIR__.'/vendor/symfony/polyfill-*/Resources/stubs') - ->name('*.php'), - false, - ), -); - -$symfonyDeprecationContracts = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - Finder::create() - ->files() - ->in(__DIR__.'/vendor/symfony/deprecation-contracts') - ->name('*.php'), - false, - ), -); - return [ 'whitelist' => [ Finder::class, ], - 'exclude-namespaces' => [ - 'Symfony\Polyfill', - ], + 'expose-global-functions' => true, + 'expose-global-classes' => true, 'exclude-constants' => [ // Symfony global constants '/^SYMFONY\_[\p{L}_]+$/', ], - 'exclude-files' => [ - ...$jetBrainStubs, - ...$polyfillsBootstraps, - ...$polyfillsStubs, - ...$symfonyDeprecationContracts, - ], + 'exclude-files' => $jetBrainStubs, 'patchers' => [ // // PHPStorm stub map: leave it unchanged diff --git a/specs/class-const/global-scope-single-level.php b/specs/class-const/global-scope-single-level.php index a8069aab..a27191db 100644 --- a/specs/class-const/global-scope-single-level.php +++ b/specs/class-const/global-scope-single-level.php @@ -55,6 +55,9 @@ class Command 'Constant call on a class belonging to the global namespace which is excluded' => [ 'exclude-namespaces' => ['/^$/'], + 'expected-recorded-classes' => [ + ['Command', 'Humbug\Command'], + ], 'payload' => <<<'PHP' [ 'exclude-namespaces' => ['/^$/'], + 'expected-recorded-classes' => [ + ['Command', 'Humbug\Command'], + ], 'payload' => <<<'PHP' [ 'exclude-namespaces' => ['/^$/'], + 'expected-recorded-classes' => [ + ['A', 'Humbug\A'], + ], 'payload' => <<<'PHP' [ 'exclude-namespaces' => ['/^$/'], 'expose-classes' => ['A'], - 'expected-recorded-classes' => [], + 'expected-recorded-classes' => [ + ['A', 'Humbug\A'], + ], 'payload' => <<<'PHP' [ 'exclude-namespaces' => ['/^$/'], + 'expected-recorded-classes' => [ + ['A', 'Humbug\A'], + ['B', 'Humbug\B'], + ['C', 'Humbug\C'], + ], 'payload' => <<<'PHP' [ + 'expected-recorded-classes' => [ + ['Normalizer', 'Humbug\Normalizer'], + ], + 'payload' => <<<'PHP' + <<<'PHP' [ 'exclude-namespaces' => [''], + 'expected-recorded-classes' => [ + ['Foo', 'Humbug\Foo'], + ], 'payload' => <<<'PHP' [ 'exclude-namespaces' => [''], 'expose-classes' => ['Foo'], - 'expected-recorded-classes' => [], + 'expected-recorded-classes' => [ + ['Foo', 'Humbug\Foo'], + ], 'payload' => <<<'PHP' enrichedReflector->isExposedClass((string) $resolvedName)) { + if ($this->shouldBeAliased($resolvedName->toString())) { $this->symbolsRegistry->recordClass( $resolvedName, FullyQualifiedFactory::concat($this->prefix, $resolvedName), @@ -74,4 +74,18 @@ public function enterNode(Node $node): Node return $node; } + + private function shouldBeAliased(string $resolvedName): bool + { + if ($this->enrichedReflector->isExposedClass($resolvedName)) { + return true; + } + + // Excluded global classes (for which we found a declaration) need to be + // aliased since otherwise any usage will not point to the prefixed + // version (since it's an alias) but the declaration will now declare + // a prefixed version (due to the namespace). + return $this->enrichedReflector->belongsToGlobalNamespace($resolvedName) + && $this->enrichedReflector->isClassExcluded($resolvedName); + } }