From ae64592ba0d6b97595393eae2b175c32581f8c8f 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:10:28 +0200 Subject: [PATCH] Allow to manage dot files as usual --- src/Finder.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Finder.php b/src/Finder.php index 68a6a3216a4..91ba3d3b6f0 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; + }))); + } } }