-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix PHPStan extension for matchAllStrictGroups #38
Conversation
@@ -82,19 +82,9 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod | |||
} | |||
|
|||
if ( | |||
in_array($methodReflection->getName(), ['matchStrictGroups', 'isMatchStrictGroups'], true) | |||
&& count($matchedType->getConstantArrays()) === 1 | |||
in_array($methodReflection->getName(), ['matchStrictGroups', 'isMatchStrictGroups', 'matchAllStrictGroups', 'isMatchAllStrictGroups'], true) |
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 IF case was missing 'matchAllStrictGroups', 'isMatchAllStrictGroups'
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.
Yeah I tried that without success tho. But now with the traverser looks much better, thanks!
@@ -34,4 +39,32 @@ static public function getType(?Arg $flagsArg, Scope $scope): ?Type | |||
} | |||
return TypeCombinator::union(...$internalFlagsTypes); | |||
} | |||
|
|||
static public function removeNullFromMatches(Type $matchesType): Type |
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.
moved this out into the utility class to ease re-use without duplication
@@ -44,6 +44,10 @@ public function testRule(): void | |||
'The isMatchStrictGroups call is potentially unsafe as $matches\' type could not be inferred.', | |||
86, | |||
], | |||
[ | |||
'The isMatchAllStrictGroups call is unsafe as match groups "test", "1" are optional and may be null.', |
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.
I am not 100% sure this error is expected, as I don't got the use-case of the rule
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 new warning is correct/fine.
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.
The point of StrictGroups methods is, the method returns only non-null matches, but if one is null it throws, so it isn't safe to use with nullable match groups, which is what this warns about. In the test though you want nullable match groups to ensure they appear not-null in $matches.
//cc @Seldaek |
Great thanks! |
closes #34