1313
1414use PhpCsFixer \Config ;
1515use PhpCsFixer \Finder ;
16+ use SplFileInfo ;
1617
1718
1819final class FixerFactory
@@ -83,13 +84,12 @@ final class FixerFactory
8384 ];
8485
8586 /**
86- * @param string $packageName
87- * @param string $workingDir
88- * @param callable[] $filters fn(SplFileInfo) => bool - false will ignore file
87+ * @param string $packageName
88+ * @param string $workingDir
8989 *
9090 * @return Config
9191 */
92- public static function createFor (string $ packageName , string $ workingDir, array $ filters = [] ): Config
92+ public static function createFor (string $ packageName , string $ workingDir ): Config
9393 {
9494 self ::$ rules ['header_comment ' ]['header ' ] = str_replace ('{{name}} ' , $ packageName , self ::HEADER );
9595 self ::$ rules ['no_extra_blank_lines ' ]['tokens ' ] = [
@@ -108,16 +108,18 @@ public static function createFor(string $packageName, string $workingDir, array
108108 self ::$ rules ['Polymorphine/declare_strict_first_line ' ] = true ;
109109 self ::$ rules ['Polymorphine/brace_after_multiline_param_method ' ] = true ;
110110
111- $ finder = Finder::create ()->in ($ workingDir );
112- foreach ($ filters as $ filter ) {
113- $ finder = $ finder ->filter ($ filter );
114- }
111+ $ excludeSamples = function (SplFileInfo $ file ) use ($ workingDir ) {
112+ $ filePath = $ file ->getPath ();
113+ $ testsPath = $ workingDir . DIRECTORY_SEPARATOR . 'tests ' . DIRECTORY_SEPARATOR ;
114+ $ samplesDir = DIRECTORY_SEPARATOR . 'code-samples ' . DIRECTORY_SEPARATOR ;
115+ return strpos ($ filePath , $ testsPath ) !== 0 || strpos ($ filePath , $ samplesDir ) === false ;
116+ };
115117
116118 $ config = new Config ();
117119 return $ config
118120 ->setRiskyAllowed (true )
119121 ->setRules (self ::$ rules )
120- ->setFinder ($ finder )
122+ ->setFinder (Finder:: create ()-> in ( $ workingDir )-> filter ( $ excludeSamples ) )
121123 ->setUsingCache (false )
122124 ->registerCustomFixers ([
123125 new Fixer \DoubleLineBeforeClassDefinitionFixer (),
0 commit comments