Skip to content

Commit 718ed99

Browse files
committed
Add explanation
1 parent b96fa28 commit 718ed99

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Util/FileMatcher.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
* - https://en.wikipedia.org/wiki/Glob_(programming)
2626
* - https://man7.org/linux/man-pages/man7/glob.7.html
2727
*
28+
* The file matcher compiles the regex in three passes:
29+
*
30+
* - Tokenise interesting chars in the glob grammar.
31+
* - Process the tokens and reorient them to produce regex.
32+
* - Map the processed tokens to regular expression segments.
33+
*
2834
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
2935
*
3036
* @internal This class is not covered by the backward compatibility promise for PHPUnit
@@ -53,7 +59,17 @@
5359
public static function toRegEx(string $glob): FileMatcherRegex
5460
{
5561
$tokens = self::tokenize($glob);
56-
$regex = '';
62+
$tokens = self::processTokens($tokens);
63+
64+
return self::mapToRegex($tokens);
65+
}
66+
67+
/**
68+
* @param list<token> $tokens
69+
*/
70+
public static function mapToRegex(array $tokens): FileMatcherRegex
71+
{
72+
$regex = '';
5773

5874
foreach ($tokens as $token) {
5975
$type = $token[0];
@@ -111,7 +127,7 @@ private static function tokenize(string $glob): array
111127
};
112128
}
113129

114-
return self::processTokens($tokens);
130+
return $tokens;
115131
}
116132

117133
/**

0 commit comments

Comments
 (0)