diff --git a/src/Finder.php b/src/Finder.php index 68a6a3216a4..a49a6bbac8f 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -13,6 +13,7 @@ namespace PhpCsFixer; use Symfony\Component\Finder\Finder as BaseFinder; +use Symfony\Component\Finder\Iterator\LazyIterator; /** * @author Fabien Potencier @@ -27,11 +28,19 @@ public function __construct() $this ->files() ->name('*.php') - ->ignoreDotFiles(false) - ->notPath('~(^|/)\.(?!php_cs(\.dist)?(/|$)).+(/|$)~') - ->name('.php_cs') - ->name('.php_cs.dist') ->exclude('vendor') ; + + // 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+) + $mainIterator = $this; // @phpstan-ignore-line + $this->append(new \IteratorIterator(new LazyIterator(function () use ($mainIterator) { + $iterator = clone $mainIterator; + $iterator->ignoreDotFiles(false); + $iterator->name('~^\.php_cs(?:\..+)?$~is'); + + return $iterator; + }))); + } } }