diff --git a/src/Finder.php b/src/Finder.php index 799c6de4b79..2c5dbbeefb7 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -13,7 +13,6 @@ namespace PhpCsFixer; use Symfony\Component\Finder\Finder as BaseFinder; -use Symfony\Component\Finder\Iterator\LazyIterator; /** * @author Fabien Potencier @@ -30,16 +29,25 @@ 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'); + + $fx = \Closure::bind(function () { // rebound function can be called without assigment as of PHP 7 + return $this->ignore & static::IGNORE_DOT_FILES; + }, $this, parent::class); + $isDotFilesIgnored = $fx(); + if ($isDotFilesIgnored) { + $this + ->ignoreDotFiles(false) + ->notPath('~(?:^|/)(?!'.$configFilenameRegex.'(?:/|$))\..*(?:/|$)~') + ; } + + return parent::getIterator(); } }