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
25
+ use function array_map ;
26
+ use function array_reduce ;
27
+ use function array_shift ;
23
28
use function sprintf ;
24
29
use function strlen ;
25
30
use function substr ;
@@ -36,14 +41,29 @@ final class FileCollector
36
41
* This takes into account the presence of cached & fresh MetaEntry
37
42
* objects, and avoids adding files to the parse queue that have
38
43
* not changed and whose direct dependencies have not changed.
44
+ *
45
+ * @param string[] $excludedPaths
39
46
*/
40
- public function collect (FilesystemInterface $ filesystem , string $ directory , string $ extension ): Files
47
+ public function collect (FilesystemInterface $ filesystem , string $ directory , string $ extension, array $ excludedPaths = [] ): Files
41
48
{
42
49
$ directory = trim ($ directory , '/ ' );
50
+ $ specification = new AndSpecification (new InPath (new Path ($ directory )), new HasExtension ([$ extension ]));
51
+ if ($ excludedPaths ) {
52
+ $ excludedSpecifications = array_map (static fn (string $ path ) => new NotSpecification (new InPath (new Path ($ path ))), $ excludedPaths );
53
+ $ excludedSpecification = array_shift ($ excludedSpecifications );
54
+
55
+ $ specification = new AndSpecification (
56
+ $ specification ,
57
+ array_reduce (
58
+ $ excludedSpecifications ,
59
+ static fn (SpecificationInterface $ carry , SpecificationInterface $ spec ) => new AndSpecification ($ carry , $ spec ),
60
+ $ excludedSpecification ,
61
+ ),
62
+ );
63
+ }
64
+
43
65
/** @var array<array<string>> $files */
44
- $ files = $ filesystem ->find (
45
- new AndSpecification (new InPath (new Path ($ directory )), new HasExtension ([$ extension ])),
46
- );
66
+ $ files = $ filesystem ->find ($ specification );
47
67
48
68
// completely populate the splFileInfos property
49
69
$ this ->fileInfos = [];
0 commit comments