Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 1, 2023
1 parent c054e51 commit 722f4a3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
83 changes: 43 additions & 40 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();
Expand All @@ -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
//
Expand Down
9 changes: 1 addition & 8 deletions src/Console/Command/InspectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/Symbol/Reflector/PhpStormStubsReflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,7 +142,6 @@ public static function provideFunctions(): iterable
yield 'PHPDBG internal function' => [
'phpdbg_break_file',
true,
event_add()
];
}

Expand Down

0 comments on commit 722f4a3

Please sign in to comment.