Skip to content

Commit

Permalink
fix: Correctly include all the JetBrains' stubs as excluded files (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Nov 1, 2023
1 parent aadfd24 commit 6cac228
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,38 @@
*/

$jetBrainStubs = (static function (): array {
$packageDir = __DIR__.'/vendor/jetbrains/phpstorm-stubs';
$ignoredDirectories = [
$packageDir.'/tests',
$packageDir.'/meta',
];
$files = [];

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()) {
$collectFiles = static function (RecursiveIteratorIterator $iterator) use (&$files, $ignoredDirectories): void {
foreach ($iterator as $fileInfo) {
/** @var SplFileInfo $fileInfo */
if (str_starts_with($fileInfo->getFilename(), '.')
|| $fileInfo->isDir()
|| !$fileInfo->isReadable()
|| 'php' !== $fileInfo->getExtension()
// The map needs to be excluded from "exclude-files" as otherwise its namespace cannot be corrected
// via a patcher
|| $fileInfo->getFilename() === 'PhpStormStubsMap.php'
) {
continue;
}

if (1 !== preg_match('/\.php$/', $fileInfo->getBasename())) {
continue;
foreach ($ignoredDirectories as $ignoredDirectory) {
if (str_starts_with($fileInfo->getPathname(), $ignoredDirectory)) {
continue 2;
}
}

$files[] = $fileInfo->getPathName();
}
}
};

$collectFiles(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($packageDir)));

return $files;
})();
Expand All @@ -50,14 +55,18 @@
'exclude-classes' => [
'Isolated\Symfony\Component\Finder\Finder',
],
'exclude-functions' => [
'trigger_deprecation',
],
'exclude-constants' => [
// Symfony global constants
'/^SYMFONY\_[\p{L}_]+$/',
],
'exclude-files' => $jetBrainStubs,
'patchers' => [
//
// PHPStorm stub map: leave it unchanged
// PHPStorm stub map: adjust the namespace to fix the autoloading, but keep it
// unchanged otherwise.
//
static function (string $filePath, string $prefix, string $contents): string {
if ('vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php' !== $filePath) {
Expand Down

0 comments on commit 6cac228

Please sign in to comment.