-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into test/phpunit
- Loading branch information
Showing
4 changed files
with
105 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>, | ||
* Pádraic Brady <padraic.brady@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
// should be kept intact except for its namespace, which needs to be prefixed, as otherwise, | ||
// its autoloading would break. | ||
|
||
return static function ( | ||
?string $stubsMapPath = null, | ||
?string $stubsMapVendorPath = null, | ||
): Closure { | ||
$stubsMapVendorPath ??= 'vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php'; | ||
$stubsMapPath ??= __DIR__.'/../'.$stubsMapVendorPath; | ||
|
||
$stubsMapOriginalContent = file_get_contents($stubsMapPath); | ||
|
||
if (!preg_match('/class PhpStormStubsMap([\s\S]+)/', $stubsMapOriginalContent, $matches)) { | ||
throw new InvalidArgumentException('Could not capture the map original content.'); | ||
} | ||
|
||
$stubsMapClassOriginalContent = $matches[1]; | ||
|
||
return static function (string $filePath, string $prefix, string $contents) use ( | ||
$stubsMapVendorPath, | ||
$stubsMapClassOriginalContent, | ||
): string { | ||
if ($filePath !== $stubsMapVendorPath) { | ||
return $contents; | ||
} | ||
|
||
return preg_replace( | ||
'/class PhpStormStubsMap([\s\S]+)/', | ||
'class PhpStormStubsMap'.$stubsMapClassOriginalContent, | ||
$contents, | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>, | ||
* Pádraic Brady <padraic.brady@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
// excluded, see scoper-phpstorm-stubs-map-patcher.php for more information. | ||
|
||
$defaultSource = __DIR__.'/../vendor/jetbrains/phpstorm-stubs'; | ||
|
||
return static function (?string $stubsDir = null) use ($defaultSource): array { | ||
$packageDir = $stubsDir ?? $defaultSource; | ||
$ignoredDirectories = [ | ||
$packageDir.'/tests', | ||
$packageDir.'/meta', | ||
]; | ||
$files = []; | ||
|
||
$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; | ||
} | ||
|
||
foreach ($ignoredDirectories as $ignoredDirectory) { | ||
if (str_starts_with($fileInfo->getPathname(), $ignoredDirectory)) { | ||
continue 2; | ||
} | ||
} | ||
|
||
$files[] = $fileInfo->getPathName(); | ||
} | ||
}; | ||
|
||
$collectFiles(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($packageDir))); | ||
|
||
return $files; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters