9
9
*/
10
10
namespace PHPUnit \TextUI \Configuration ;
11
11
12
+ use PHPUnit \Util \FileMatcher ;
13
+ use PHPUnit \Util \FileMatcherRegex ;
14
+
15
+
12
16
/**
13
17
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
14
18
*
@@ -18,19 +22,23 @@ final class SourceFilter
18
22
{
19
23
private static ?self $ instance = null ;
20
24
25
+ private Source $ source ;
26
+
21
27
/**
22
- * @var array<non-empty-string, true >
28
+ * @var list<FileMatcherRegex >
23
29
*/
24
- private readonly array $ map ;
30
+ private array $ includeDirectoryRegexes ;
31
+
32
+ /**
33
+ * @var list<FileMatcherRegex>
34
+ */
35
+ private array $ excludeDirectoryRegexes ;
25
36
26
37
public static function instance (): self
27
38
{
28
39
if (self ::$ instance === null ) {
29
- self ::$ instance = new self (
30
- (new SourceMapper )->map (
31
- Registry::get ()->source (),
32
- ),
33
- );
40
+ $ source = Registry::get ()->source ();
41
+ return new self ($ source );
34
42
}
35
43
36
44
return self ::$ instance ;
@@ -39,13 +47,21 @@ public static function instance(): self
39
47
/**
40
48
* @param array<non-empty-string, true> $map
41
49
*/
42
- public function __construct (array $ map )
50
+ public function __construct (Source $ source )
43
51
{
44
- $ this ->map = $ map ;
52
+ $ this ->source = $ source ;
53
+ $ this ->includeDirectoryRegexes = array_map (function (FilterDirectory $ directory ) {
54
+ return FileMatcher::toRegEx ($ directory ->path ());
55
+ }, $ source ->includeDirectories ()->asArray ());
56
+ $ this ->excludeDirectoryRegexes = array_map (function (FilterDirectory $ directory ) {
57
+ return FileMatcher::toRegEx ($ directory ->path ());
58
+ }, $ source ->excludeDirectories ()->asArray ());
45
59
}
46
60
47
61
public function includes (string $ path ): bool
48
62
{
63
+ foreach ($ this ->source ->includeDirectories () as $ directory ) {
64
+ }
49
65
return isset ($ this ->map [$ path ]);
50
66
}
51
67
}
0 commit comments