17
17
use Flyfinder \Specification \AndSpecification ;
18
18
use Flyfinder \Specification \HasExtension ;
19
19
use Flyfinder \Specification \InPath ;
20
+ use Flyfinder \Specification \NotSpecification ;
21
+ use Flyfinder \Specification \SpecificationInterface ;
20
22
use InvalidArgumentException ;
21
23
use League \Flysystem \FilesystemInterface ;
22
24
@@ -37,13 +39,26 @@ final class FileCollector
37
39
* objects, and avoids adding files to the parse queue that have
38
40
* not changed and whose direct dependencies have not changed.
39
41
*/
40
- public function collect (FilesystemInterface $ filesystem , string $ directory , string $ extension ): Files
42
+ public function collect (FilesystemInterface $ filesystem , string $ directory , string $ extension, array $ excludedPaths = [] ): Files
41
43
{
42
44
$ directory = trim ($ directory , '/ ' );
45
+ $ specification = new AndSpecification (new InPath (new Path ($ directory )), new HasExtension ([$ extension ]));
46
+ if ($ excludedPaths ) {
47
+ $ excludedSpecifications = array_map (fn (string $ path ) => new NotSpecification (new InPath (new Path ($ path ))), $ excludedPaths );
48
+ $ excludedSpecification = array_shift ($ excludedSpecifications );
49
+
50
+ $ specification = new AndSpecification (
51
+ $ specification ,
52
+ array_reduce (
53
+ $ excludedSpecifications ,
54
+ fn (SpecificationInterface $ carry , SpecificationInterface $ spec ) => new AndSpecification ($ carry , $ spec ),
55
+ $ excludedSpecification
56
+ )
57
+ );
58
+ }
59
+
43
60
/** @var array<array<string>> $files */
44
- $ files = $ filesystem ->find (
45
- new AndSpecification (new InPath (new Path ($ directory )), new HasExtension ([$ extension ])),
46
- );
61
+ $ files = $ filesystem ->find ($ specification );
47
62
48
63
// completely populate the splFileInfos property
49
64
$ this ->fileInfos = [];
0 commit comments