diff --git a/.php_cs.dist b/.php_cs.dist index 1c9ea9b79da..e33c2514d56 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,5 +1,15 @@ + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + $header = <<<'EOF' This file is part of PHP CS Fixer. @@ -39,7 +49,8 @@ if (false !== getenv('FABBOT_IO')) { PhpCsFixer\FixerFactory::create() ->registerBuiltInFixers() ->registerCustomFixers($config->getCustomFixers()) - ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())); + ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())) + ; } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) { $config->setRules([]); } catch (UnexpectedValueException $e) { diff --git a/phpstan.neon b/phpstan.neon index 18dac5ccec8..81cfe54474a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -60,4 +60,8 @@ parameters: message: '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/' path: src/Tokenizer/Tokens.php + - # https://github.com/phpstan/phpstan/issues/4808 + message: '/^Access to private property \$ignore of parent class Symfony\\Component\\Finder\\Finder\.$/' + path: src/Finder.php + tipsOfTheDay: false diff --git a/src/Finder.php b/src/Finder.php index 807a633f4f5..2c5dbbeefb7 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -30,4 +30,24 @@ public function __construct() ->exclude('vendor') ; } + + public function getIterator() + { + // add config files even if dot files are ignored + $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(); + } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 780e9a808d8..6ba0a9c6abd 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -127,8 +127,13 @@ public function testThatFinderWorksWithDirSetOnConfig() false ); - static::assertCount(1, $items); - static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertCount(3, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); + static::assertSame('.php_cs', $items[0]->getFilename()); + static::assertSame('.php_cs.dist', $items[1]->getFilename()); + static::assertSame('somefile.php', $items[2]->getFilename()); } public function testThatCustomFinderWorks() @@ -143,8 +148,13 @@ public function testThatCustomFinderWorks() false ); - static::assertCount(1, $items); - static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertCount(3, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); + static::assertSame('.php_cs', $items[0]->getFilename()); + static::assertSame('.php_cs.dist', $items[1]->getFilename()); + static::assertSame('somefile.php', $items[2]->getFilename()); } public function testThatCustomSymfonyFinderWorks() @@ -159,8 +169,12 @@ public function testThatCustomSymfonyFinderWorks() false ); - static::assertCount(1, $items); + static::assertCount(2, $items); + usort($items, function (\SplFileInfo $a, \SplFileInfo $b) { + return strcmp($a->getFilename(), $b->getFilename()); + }); static::assertSame('somefile.php', $items[0]->getFilename()); + static::assertSame('somefile2.php.txt', $items[1]->getFilename()); } public function testThatCacheFileHasDefaultValue() diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index bd04936ab9f..98f72b7c0ed 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -565,14 +565,14 @@ static function ($item) use ($dir) { ], 'configured only by finder' => [ // don't override if the argument is empty - $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), + $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/.php_cs', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), Finder::create() ->in($dir), [], 'override', ], 'configured only by argument' => [ - $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), + $cb(['a1.php', 'a2.php', 'b/b1.php', 'b/b2.php', 'b_b/b_b1.php', 'c/c1.php', 'c/d/cd1.php', 'd/.php_cs', 'd/d1.php', 'd/d2.php', 'd/e/de1.php', 'd/f/df1.php']), Finder::create(), [$dir], 'override', diff --git a/tests/Fixtures/FinderDirectory/.php_cs b/tests/Fixtures/FinderDirectory/.php_cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/FinderDirectory/.php_cs.dist b/tests/Fixtures/FinderDirectory/.php_cs.dist new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/FinderDirectory/somefile2.php.txt b/tests/Fixtures/FinderDirectory/somefile2.php.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/Fixtures/ci-integration/.php_cs.dist b/tests/Fixtures/ci-integration/.php_cs.dist index 088317ac351..4faae3319cb 100644 --- a/tests/Fixtures/ci-integration/.php_cs.dist +++ b/tests/Fixtures/ci-integration/.php_cs.dist @@ -1,9 +1,9 @@ setRules(array( + ->setRules([ '@Symfony' => true, - )) + ]) ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__) diff --git a/tests/Smoke/CiIntegrationTest.php b/tests/Smoke/CiIntegrationTest.php index 79a94eee57c..b25327fd0f0 100644 --- a/tests/Smoke/CiIntegrationTest.php +++ b/tests/Smoke/CiIntegrationTest.php @@ -219,7 +219,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '....', ], 'changes-including-custom-config-file-creation' => [ 'changes-including-custom-config-file-creation', @@ -238,7 +238,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '.....', ], 'changes-including-composer-lock' => [ 'changes-including-composer-lock', @@ -257,7 +257,7 @@ public function provideIntegrationCases() '', '', ], - '...', + '....', ], ]; }