Skip to content

Commit 7be89ae

Browse files
Merge branch '3.4' into 4.2
* 3.4: (24 commits) Apply php-cs-fixer rule for array_key_exists() [Security] Change FormAuthenticator if condition handles multi-byte characters in autocomplete speed up tests running them without debug flag [Translations] added missing Croatian validators Fix getItems() performance issue with RedisCluster (php-redis) [VarDumper] Keep a ref to objects to ensure their handle cannot be reused while cloning IntegerType: reject submitted non-integer numbers be keen to newcomers [HttpKernel] Fix possible infinite loop of exceptions fixed CS [Validator] Added missing translations for Afrikaans do not validate non-submitted form fields in PATCH requests Update usage example in ArrayInput doc block. [Console] Prevent ArgvInput::getFirstArgument() from returning an option value [Validator] Fixed duplicate UUID fixed CS [EventDispatcher] Fix unknown priority Avoid mutating the Finder when building the iterator [Validator] Add the missing translations for the Greek (el) locale ...
2 parents f376d51 + 80f472c commit 7be89ae

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

Finder.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* All rules may be invoked several times.
3131
*
32-
* All methods return the current Finder object to allow easy chaining:
32+
* All methods return the current Finder object to allow chaining:
3333
*
3434
* $finder = Finder::create()->files()->name('*.php')->in(__DIR__);
3535
*
@@ -674,12 +674,15 @@ public function count()
674674

675675
private function searchInDirectory(string $dir): \Iterator
676676
{
677+
$exclude = $this->exclude;
678+
$notPaths = $this->notPaths;
679+
677680
if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
678-
$this->exclude = array_merge($this->exclude, self::$vcsPatterns);
681+
$exclude = array_merge($exclude, self::$vcsPatterns);
679682
}
680683

681684
if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
682-
$this->notPaths[] = '#(^|/)\..+(/|$)#';
685+
$notPaths[] = '#(^|/)\..+(/|$)#';
683686
}
684687

685688
$minDepth = 0;
@@ -712,8 +715,8 @@ private function searchInDirectory(string $dir): \Iterator
712715

713716
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
714717

715-
if ($this->exclude) {
716-
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
718+
if ($exclude) {
719+
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $exclude);
717720
}
718721

719722
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
@@ -746,8 +749,8 @@ private function searchInDirectory(string $dir): \Iterator
746749
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
747750
}
748751

749-
if ($this->paths || $this->notPaths) {
750-
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
752+
if ($this->paths || $notPaths) {
753+
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $notPaths);
751754
}
752755

753756
if ($this->sort || $this->reverseSorting) {

Tests/FinderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,18 @@ public function testIgnoreVCS()
421421
]), $finder->in(self::$tmpDir)->getIterator());
422422
}
423423

424+
public function testIgnoreVCSCanBeDisabledAfterFirstIteration()
425+
{
426+
$finder = $this->buildFinder();
427+
$finder->in(self::$tmpDir);
428+
$finder->ignoreDotFiles(false);
429+
430+
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
431+
432+
$finder->ignoreVCS(false);
433+
$this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
434+
}
435+
424436
public function testIgnoreDotFiles()
425437
{
426438
$finder = $this->buildFinder();
@@ -496,6 +508,17 @@ public function testIgnoreDotFiles()
496508
]), $finder->in(self::$tmpDir)->getIterator());
497509
}
498510

511+
public function testIgnoreDotFilesCanBeDisabledAfterFirstIteration()
512+
{
513+
$finder = $this->buildFinder();
514+
$finder->in(self::$tmpDir);
515+
516+
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->getIterator());
517+
518+
$finder->ignoreDotFiles(false);
519+
$this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
520+
}
521+
499522
public function testSortByName()
500523
{
501524
$finder = $this->buildFinder();

0 commit comments

Comments
 (0)