99 */
1010namespace PHPUnit \TextUI \Configuration ;
1111
12+ use PHPUnit \Util \FileMatcher ;
13+ use PHPUnit \Util \FileMatcherRegex ;
14+
15+
1216/**
1317 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
1418 *
@@ -18,19 +22,23 @@ final class SourceFilter
1822{
1923 private static ?self $ instance = null ;
2024
25+ private Source $ source ;
26+
2127 /**
22- * @var array<non-empty-string, true >
28+ * @var list<FileMatcherRegex >
2329 */
24- private readonly array $ map ;
30+ private array $ includeDirectoryRegexes ;
31+
32+ /**
33+ * @var list<FileMatcherRegex>
34+ */
35+ private array $ excludeDirectoryRegexes ;
2536
2637 public static function instance (): self
2738 {
2839 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 );
3442 }
3543
3644 return self ::$ instance ;
@@ -39,13 +47,21 @@ public static function instance(): self
3947 /**
4048 * @param array<non-empty-string, true> $map
4149 */
42- public function __construct (array $ map )
50+ public function __construct (Source $ source )
4351 {
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 ());
4559 }
4660
4761 public function includes (string $ path ): bool
4862 {
63+ foreach ($ this ->source ->includeDirectories () as $ directory ) {
64+ }
4965 return isset ($ this ->map [$ path ]);
5066 }
5167}
0 commit comments