diff --git a/scoper.inc.php b/scoper.inc.php index 3c2d38c72..e99996fd1 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -13,35 +13,33 @@ */ $jetBrainStubs = (static function (): array { - $packageDir = __DIR__.'/vendor/jetbrains/phpstorm-stubs'; $files = []; - $ignoredDirectories = [ - $packageDir.'/tests', - $packageDir.'/meta', - ]; - $collectFiles = static function (RecursiveIteratorIterator $iterator) use (&$collectFiles, &$files, $ignoredDirectories): void { - foreach ($iterator as $fileInfo) { - /** @var SplFileInfo $fileInfo */ - if (str_starts_with($fileInfo->getFilename(), '.') - || $fileInfo->isDir() - || !$fileInfo->isReadable() - || 'php' !== $fileInfo->getExtension() - ) { + foreach (new DirectoryIterator(__DIR__.'/vendor/jetbrains/phpstorm-stubs') as $directoryInfo) { + if ($directoryInfo->isDot()) { + continue; + } + + if (false === $directoryInfo->isDir()) { + continue; + } + + if (in_array($directoryInfo->getBasename(), ['tests', 'meta'], true)) { + continue; + } + + foreach (new DirectoryIterator($directoryInfo->getPathName()) as $fileInfo) { + if ($fileInfo->isDot()) { continue; } - foreach ($ignoredDirectories as $ignoredDirectory) { - if (str_starts_with($fileInfo->getPathname(), $ignoredDirectory)) { - continue 2; - } + if (1 !== preg_match('/\.php$/', $fileInfo->getBasename())) { + continue; } $files[] = $fileInfo->getPathName(); } - }; - - $collectFiles(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($packageDir))); + } return $files; })(); @@ -52,32 +50,37 @@ 'exclude-classes' => [ 'Isolated\Symfony\Component\Finder\Finder', ], - 'exclude-functions' => [ - // symfony/deprecation-contracts - 'trigger_deprecation', - - // nikic/php-parser - // https://github.com/nikic/PHP-Parser/issues/957 - 'assertArgs', - 'ensureDirExists', - 'execCmd', - 'formatErrorMessage', - 'magicSplit', - 'parseArgs', - 'preprocessGrammar', - 'regex', - 'removeTrailingWhitespace', - 'resolveMacros', - 'resolveNodes', - 'resolveStackAccess', - 'showHelp', - ], 'exclude-constants' => [ // Symfony global constants '/^SYMFONY\_[\p{L}_]+$/', ], 'exclude-files' => $jetBrainStubs, 'patchers' => [ + // + // PHPStorm stub map: leave it unchanged + // + static function (string $filePath, string $prefix, string $contents): string { + if ('vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php' !== $filePath) { + return $contents; + } + + return str_replace( + [ + $prefix.'\\\\', + $prefix.'\\', + 'namespace JetBrains\PHPStormStub;', + ], + [ + '', + '', + sprintf( + 'namespace %s\JetBrains\PHPStormStub;', + $prefix, + ), + ], + $contents, + ); + }, // // Reflector: leave the registered internal symbols unchanged // diff --git a/src/Console/Command/InspectCommand.php b/src/Console/Command/InspectCommand.php index 221bb2a2b..5a2d578d4 100644 --- a/src/Console/Command/InspectCommand.php +++ b/src/Console/Command/InspectCommand.php @@ -34,7 +34,6 @@ use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use function array_key_exists; -use function file_exists; use function Safe\getcwd; use function sprintf; use const DIRECTORY_SEPARATOR; @@ -158,13 +157,7 @@ private function getConfigFilePath(IO $io, string $cwd): ?string { $configFilePath = (string) $io->getOption(self::CONFIG_FILE_OPT)->asNullableString(); - if ('' !== $configFilePath) { - return $this->canonicalizePath($configFilePath, $cwd); - } - - $defaultConfigFilePath = $this->canonicalizePath(ConfigurationFactory::DEFAULT_FILE_NAME, $cwd); - - return file_exists($defaultConfigFilePath) ? $defaultConfigFilePath : null; + return '' === $configFilePath ? null : $this->canonicalizePath($configFilePath, $cwd); } /** diff --git a/tests/Symbol/Reflector/PhpStormStubsReflectorTest.php b/tests/Symbol/Reflector/PhpStormStubsReflectorTest.php index 2aea6b906..63b350172 100644 --- a/tests/Symbol/Reflector/PhpStormStubsReflectorTest.php +++ b/tests/Symbol/Reflector/PhpStormStubsReflectorTest.php @@ -16,8 +16,6 @@ use Humbug\PhpScoper\Symbol\Reflector; use PHPUnit\Framework\TestCase; -use function event_add; -use function event_base_reinit; /** * @covers \Humbug\PhpScoper\Symbol\Reflector @@ -144,7 +142,6 @@ public static function provideFunctions(): iterable yield 'PHPDBG internal function' => [ 'phpdbg_break_file', true, - event_add() ]; }