mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Use callable to filter files in FileProvider::getFilesInDir()
This commit is contained in:
parent
f2db139b15
commit
a514df2bb7
@ -57,13 +57,13 @@ class FakeFileProvider extends FileProvider
|
||||
|
||||
/**
|
||||
* @param array<string> $file_extensions
|
||||
* @param null|callable(string):bool $directory_filter
|
||||
* @param null|callable(string):bool $filter
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFilesInDir(string $dir_path, array $file_extensions, callable $directory_filter = null): array
|
||||
public function getFilesInDir(string $dir_path, array $file_extensions, callable $filter = null): array
|
||||
{
|
||||
$file_paths = parent::getFilesInDir($dir_path, $file_extensions, $directory_filter);
|
||||
$file_paths = parent::getFilesInDir($dir_path, $file_extensions, $filter);
|
||||
|
||||
foreach ($this->fake_files as $file_path => $_) {
|
||||
if (strpos(strtolower($file_path), strtolower($dir_path)) === 0) {
|
||||
|
@ -118,11 +118,11 @@ class FileProvider
|
||||
|
||||
/**
|
||||
* @param array<string> $file_extensions
|
||||
* @param null|callable(string):bool $directory_filter
|
||||
* @param null|callable(string):bool $filter
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFilesInDir(string $dir_path, array $file_extensions, callable $directory_filter = null): array
|
||||
public function getFilesInDir(string $dir_path, array $file_extensions, callable $filter = null): array
|
||||
{
|
||||
$file_paths = [];
|
||||
|
||||
@ -131,12 +131,18 @@ class FileProvider
|
||||
FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS
|
||||
);
|
||||
|
||||
if ($directory_filter !== null) {
|
||||
if ($filter !== null) {
|
||||
$iterator = new RecursiveCallbackFilterIterator(
|
||||
$iterator,
|
||||
/** @param mixed $_ */
|
||||
function (string $current, $_, RecursiveIterator $iterator) use ($directory_filter): bool {
|
||||
return !$iterator->hasChildren() || $directory_filter($current . DIRECTORY_SEPARATOR);
|
||||
function (string $current, $_, RecursiveIterator $iterator) use ($filter): bool {
|
||||
if ($iterator->hasChildren()) {
|
||||
$path = $current . DIRECTORY_SEPARATOR;
|
||||
} else {
|
||||
$path = $current;
|
||||
}
|
||||
|
||||
return $filter($path);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user