Skip to content

Commit

Permalink
Merge pull request #1477 from staabm/simple
Browse files Browse the repository at this point in the history
Simplify `FileIteratorSourceLocator`, prevent stat calls on paths that aren't PHP files
  • Loading branch information
Ocramius authored Jan 6, 2025
2 parents 0101c76 + a537c0f commit 9a39c1f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/SourceLocator/Type/FileIteratorSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
use function array_map;
use function array_values;
use function iterator_to_array;
use function pathinfo;

use const PATHINFO_EXTENSION;

/**
* This source locator loads all php files from \FileSystemIterator
Expand Down Expand Up @@ -56,13 +53,11 @@ private function getAggregatedSourceLocator(): AggregateSourceLocator
return $this->aggregateSourceLocator
?? $this->aggregateSourceLocator = new AggregateSourceLocator(array_values(array_filter(array_map(
function (SplFileInfo $item): SingleFileSourceLocator|null {
$realPath = $item->getRealPath();

if (! ($item->isFile() && pathinfo($realPath, PATHINFO_EXTENSION) === 'php')) {
if (! ($item->isFile() && $item->getExtension() === 'php')) {
return null;
}

return new SingleFileSourceLocator($realPath, $this->astLocator);
return new SingleFileSourceLocator($item->getRealPath(), $this->astLocator);
},
iterator_to_array($this->fileSystemIterator),
))));
Expand Down

0 comments on commit 9a39c1f

Please sign in to comment.