Skip to content

Commit 6cdfe93

Browse files
address review
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
1 parent a10c114 commit 6cdfe93

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/Symfony/Component/Finder/Finder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,16 +581,17 @@ public function sortByModifiedTime(): static
581581
* The anonymous function receives a \SplFileInfo and must return false
582582
* to remove files.
583583
*
584-
* When prune is enabled, directories are not traversed further.
585-
*
586584
* @param \Closure(SplFileInfo): bool $closure
587585
*
586+
* @Symfony7param bool $prune Whether to traverse directories further
587+
*
588588
* @return $this
589589
*
590590
* @see CustomFilterIterator
591591
*/
592-
public function filter(\Closure $closure, bool $prune = false): static
592+
public function filter(\Closure $closure/* , bool $prune = false */): static
593593
{
594+
$prune = \func_num_args() >= 2 ? func_get_arg(1) : false;
594595
$this->filters[] = $closure;
595596

596597
if ($prune) {

src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ public function __construct(\Iterator $iterator, array $directories)
7373
public function accept(): bool
7474
{
7575
$hasChildren = null;
76-
if (isset($this->excludedDirs[$this->getFilename()])) {
77-
$hasChildren = $this->hasChildren();
78-
79-
if ($hasChildren) {
80-
return false;
81-
}
76+
if (isset($this->excludedDirs[$this->getFilename()]) && $hasChildren = $this->hasChildren()) {
77+
return false;
8278
}
8379

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

91-
if ($this->pruneFilters) {
92-
if (null === $hasChildren) {
93-
$hasChildren = $this->hasChildren();
94-
}
95-
96-
if ($hasChildren) {
97-
foreach ($this->pruneFilters as $pruneFilter) {
98-
if (!$pruneFilter($this->current())) {
99-
return false;
100-
}
87+
if ($this->pruneFilters && $hasChildren ??= $this->hasChildren()) {
88+
foreach ($this->pruneFilters as $pruneFilter) {
89+
if (!$pruneFilter($this->current())) {
90+
return false;
10191
}
10292
}
10393
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy