9
9
*/
10
10
namespace PHPUnit \TextUI \Configuration ;
11
11
12
+ use function array_map ;
12
13
use PHPUnit \Util \FileMatcher ;
13
14
use PHPUnit \Util \FileMatcherRegex ;
14
15
15
-
16
16
/**
17
+ * TODO: Does not take into account suffixes and prefixes - and tests don't cover it.
18
+ *
17
19
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
18
20
*
19
21
* @internal This class is not covered by the backward compatibility promise for PHPUnit
20
22
*/
21
23
final class SourceFilter
22
24
{
23
25
private static ?self $ instance = null ;
24
-
25
26
private Source $ source ;
26
27
27
28
/**
@@ -38,30 +39,54 @@ public static function instance(): self
38
39
{
39
40
if (self ::$ instance === null ) {
40
41
$ source = Registry::get ()->source ();
42
+
41
43
return new self ($ source );
42
44
}
43
45
44
46
return self ::$ instance ;
45
47
}
46
48
47
- /**
48
- * @param array<non-empty-string, true> $map
49
- */
50
49
public function __construct (Source $ source )
51
50
{
52
- $ this ->source = $ source ;
53
- $ this ->includeDirectoryRegexes = array_map (function (FilterDirectory $ directory ) {
51
+ $ this ->source = $ source ;
52
+ $ this ->includeDirectoryRegexes = array_map (static function (FilterDirectory $ directory )
53
+ {
54
54
return FileMatcher::toRegEx ($ directory ->path ());
55
55
}, $ source ->includeDirectories ()->asArray ());
56
- $ this ->excludeDirectoryRegexes = array_map (function (FilterDirectory $ directory ) {
56
+ $ this ->excludeDirectoryRegexes = array_map (static function (FilterDirectory $ directory )
57
+ {
57
58
return FileMatcher::toRegEx ($ directory ->path ());
58
59
}, $ source ->excludeDirectories ()->asArray ());
59
60
}
60
61
61
62
public function includes (string $ path ): bool
62
63
{
63
- foreach ($ this ->source ->includeDirectories () as $ directory ) {
64
+ $ included = false ;
65
+
66
+ foreach ($ this ->source ->includeFiles () as $ file ) {
67
+ if ($ file ->path () === $ path ) {
68
+ $ included = true ;
69
+ }
64
70
}
65
- return isset ($ this ->map [$ path ]);
71
+
72
+ foreach ($ this ->includeDirectoryRegexes as $ directoryRegex ) {
73
+ if ($ directoryRegex ->matches ($ path )) {
74
+ $ included = true ;
75
+ }
76
+ }
77
+
78
+ foreach ($ this ->source ->excludeFiles () as $ file ) {
79
+ if ($ file ->path () === $ path ) {
80
+ $ included = false ;
81
+ }
82
+ }
83
+
84
+ foreach ($ this ->excludeDirectoryRegexes as $ directoryRegex ) {
85
+ if ($ directoryRegex ->matches ($ path )) {
86
+ $ included = false ;
87
+ }
88
+ }
89
+
90
+ return $ included ;
66
91
}
67
92
}
0 commit comments