Strings::match() should be checked for invalid regex
enumag opened this issue · 4 comments
I recently added a rule to force using Strings::match() instead of preg_match() in my project for better API and error handling. However it seems that while PHPStan checks preg_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 for Strings::match().
This is actually very problematic because Strings::match() has the regex and haystack arguments swapped which can be easily missed when switching from preg_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?
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.