-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-6114: Static path matching #6146
base: main
Are you sure you want to change the base?
GH-6114: Static path matching #6146
Conversation
|
||
class FileMatcherPattern | ||
{ | ||
public function __construct(public string $path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will/could include the $suffix
, $prefix
and $exclude
also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or could simply remove this and handle the prefix/suffix independently of the "file matcher"
b2da2f7
to
797d6b7
Compare
Have refactored to tokenize the glob string, while less performant it's easier to reason about and we only need to compile the regex for each |
if ($bracketOpen === true && $type === self::T_BRACKET_OPEN) { | ||
// if bracket is already open, interpret everything as a | ||
// literal char | ||
$resolved[] = [self::T_CHAR, $char]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename T_CHAR => T_LITERAL?
src/Util/FileMatcher.php
Outdated
) { | ||
$resolved[] = [self::T_GLOBSTAR, '**']; | ||
|
||
// we eat the two `*` in addition to the slash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we eat two * AND the slash
792bae8
to
6f99ddc
Compare
continue; | ||
} | ||
|
||
$resolved[] = [$type, $char]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this handles any "left over tokens" - including T_ASTERISK
- maybe all tokens should be handled explicitly?
for ($i = 0; $i < $length; $i++) { | ||
$c = $glob[$i]; | ||
|
||
$tokens[] = match ($c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could inline $c
ba1d99d
to
6fc5179
Compare
self::T_BRACKET_CLOSE => ']', | ||
self::T_HYPHEN => '-', | ||
self::T_COLON => ':', | ||
self::T_BACKSLASH => '\\', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COLON and BACKSLASH are not tested
6fc5179
to
e07a96f
Compare
This (early stage) WIP PR introduces a static path matcher which intends to emulate the behavior of the PHPUnit
FileIterator
in order to prevent PHPUnit traversing the filesystem when a deprecation is triggered.The PHPUnit FileIterator uses
glob
to find directories and we therefore need to support the glob patterns - which can vary according to the platform. This PR uses https://man7.org/linux/man-pages/man7/glob.7.html as a reference in addition to testing the behavior locally to confirm assumptions.The webmozart/glob provides a similar feature however it's behavior is different as it supports curly braces, and
*
is restricted to a single directory level, while*
in PHPUnit will return all descendants and I'm sure there are other differences - however I've used that as a starting point.TODO:
[:alnum:]
etc.glob
behavior of unterminated[
character groups./a**
will match/b
and all other directories, where as/ab*
will not match anything. We can either copy that behavior or "fix" it.and maybe writing the implementation from scratch if regex turns out to be a bad fit.Usages on Github:
directory.*\[
): 0: https://github.com/search?q=%2Fdirectory.*%5C%5B%2F+path%3A*.xml+path%3A**%2Fphpunit.xml+language%3AXML&type=code?
any char: 0 https://github.com/search?q=%2Fdirectory.*%5C%5B%2F+path%3A*.xml+path%3A**%2Fphpunit.xml+language%3AXML&type=code