-
Notifications
You must be signed in to change notification settings - Fork 506
Improve sprintf support #3310
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
Improve sprintf support #3310
Conversation
You've opened the pull request against the latest branch 1.12.x. If your code is relevant on 1.11.x and you want it to be released sooner, please rebase your pull request and change its target to 1.11.x. |
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.
@@ -125,32 +125,45 @@ public function getTypeFromFunctionCall( | |||
return $singlePlaceholderEarlyReturn; | |||
} | |||
|
|||
if ($allPatternsNonFalsy) { |
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.
Early return to avoid the following computation.
$isNonEmpty = $allPatternsNonEmpty; | ||
if ( | ||
count($formatStrings) === 0 | ||
!$isNonEmpty |
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.
If it's already known as non empty, we don't have to compute this.
&& $functionReflection->getName() === 'sprintf' | ||
&& count($args) === 2 | ||
&& count($args) >= 2 |
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.
There was a special case for sprintf($nonEmpty, $nonEmpty, $nonEmpty) but this can be extended to sprintf($nonEmpty, $nonEmpty, $nonEmpty)
and so on.
continue; | ||
} | ||
|
||
if (!$scope->getType($arg->value)->toString()->isNonEmptyString()->yes()) { |
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 toString was added for things like IntegerRange which need to be casted before the isNonEmptyString check.
Thank you! |
Closes phpstan/phpstan#11491