Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
  • Loading branch information
mvorisek and nicolas-grekas committed Jul 13, 2023
1 parent a10c114 commit 6cdfe93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/Symfony/Component/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,17 @@ public function sortByModifiedTime(): static
* The anonymous function receives a \SplFileInfo and must return false
* to remove files.
*
* When prune is enabled, directories are not traversed further.
*
* @param \Closure(SplFileInfo): bool $closure
*
* @Symfony7param bool $prune Whether to traverse directories further
*
* @return $this
*
* @see CustomFilterIterator
*/
public function filter(\Closure $closure, bool $prune = false): static
public function filter(\Closure $closure/* , bool $prune = false */): static
{
$prune = \func_num_args() >= 2 ? func_get_arg(1) : false;
$this->filters[] = $closure;

if ($prune) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ public function __construct(\Iterator $iterator, array $directories)
public function accept(): bool
{
$hasChildren = null;
if (isset($this->excludedDirs[$this->getFilename()])) {
$hasChildren = $this->hasChildren();

if ($hasChildren) {
return false;
}
if (isset($this->excludedDirs[$this->getFilename()]) && $hasChildren = $this->hasChildren()) {
return false;
}

if ($this->excludedPattern) {
Expand All @@ -88,16 +84,10 @@ public function accept(): bool
return !preg_match($this->excludedPattern, $path);
}

if ($this->pruneFilters) {
if (null === $hasChildren) {
$hasChildren = $this->hasChildren();
}

if ($hasChildren) {
foreach ($this->pruneFilters as $pruneFilter) {
if (!$pruneFilter($this->current())) {
return false;
}
if ($this->pruneFilters && $hasChildren ??= $this->hasChildren()) {
foreach ($this->pruneFilters as $pruneFilter) {
if (!$pruneFilter($this->current())) {
return false;
}
}
}
Expand Down

0 comments on commit 6cdfe93

Please sign in to comment.