Closed enumag closed 1 year ago
I would like regex-string
in core PHPStan
That would be my preferred solution as well... Some other languages do have regex as separate type so it would make sense in my opinion.
Feel free to copy and adjust the rule :)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I recently added a rule to force using
Strings::match()
instead ofpreg_match()
in my project for better API and error handling. However it seems that while PHPStan checkspreg_match
for invalid regular expression (https://github.com/phpstan/phpstan-src/blob/1.9.x/src/Rules/Regexp/RegularExpressionPatternRule.php) the same isn't done forStrings::match()
.This is actually very problematic because
Strings::match()
has the regex and haystack arguments swapped which can be easily missed when switching frompreg_match
and I already noticed two cases where one of my developers made that mistake.How should this be solved? Should we copy the rule from PHPStan here and adjust it? Or should the rule in PHPStan be configurable somehow to allow checking other functions and methods? Or maybe a new
regex-string
type should be added?