From 33f033abf78220a6c863713aa35f60dc57864ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 5 Apr 2021 15:59:41 +0200 Subject: [PATCH] fix unable to rewind --- src/Finder.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Finder.php b/src/Finder.php index 799c6de4b79..ead404ffde1 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -30,16 +30,24 @@ public function __construct() ->name('*.php') ->exclude('vendor') ; + } + public function getIterator() + { // add config files even if dot files are ignored - if (class_exists(LazyIterator::class)) { // LazyIterator class is available since Symfony 4.4 (which requires PHP 7+) - $this->append(new \IteratorIterator(new LazyIterator(function () { - $iterator = clone $this; - $iterator->ignoreDotFiles(false); - $iterator->name('~^\.php_cs(?:\..+)?$~is'); - - return $iterator; - }))); + $configFilenameRegex = '\.php_cs(?:\..+)?'; + $this->name('~^' . $configFilenameRegex . '$~is'); + + $isDotFilesIgnored = \Closure::bind(function () { + return $this->ignore & static::IGNORE_DOT_FILES; + }, $this, parent::class)(); + if ($isDotFilesIgnored) { + $this + ->ignoreDotFiles(false) + ->notPath('~(?:^|/)(?!' . $configFilenameRegex . '(?:/|$))\..*(?:/|$)~') + ; } + + return parent::getIterator(); } }