Skip to content

Commit 83b20de

Browse files
committed
better int range support
1 parent 93ce92a commit 83b20de

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ public function getTypeFromFunctionCall(
8181
// if the format string is just a placeholder and specified an argument
8282
// of stringy type, then the return value will be of the same type
8383
$checkArgType = $scope->getType($args[$checkArg]->value);
84-
8584
if ($matches[2] === 's'
86-
&& $checkArgType->isScalar()->yes()
87-
&& $checkArgType->getFiniteTypes() === [] // constant types will be handled in getConstantType()
85+
&& ($checkArgType->isString()->yes() || $checkArgType->isInteger()->yes())
8886
) {
8987
$singlePlaceholderEarlyReturn = $checkArgType->toString();
9088
} elseif ($matches[2] !== 's') {

tests/PHPStan/Analyser/nsrt/bug-7387.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function positionalArgs($mixed, int $i, float $f, string $s, int $posInt,
5656
assertType('numeric-string', sprintf('%2$14s', $mixed, $i));
5757
assertType('non-falsy-string&numeric-string', sprintf('%2$14s', $mixed, $posInt));
5858
assertType('non-falsy-string&numeric-string', sprintf('%2$14s', $mixed, $negInt));
59-
assertType('non-falsy-string', sprintf('%2$14s', $mixed, $intRange)); // could be numeric-string
60-
assertType('non-falsy-string', sprintf('%2$14s', $mixed, $nonZeroIntRange)); // could be non-falsy-string&numeric-string
59+
assertType('numeric-string', sprintf('%2$14s', $mixed, $intRange));
60+
assertType('non-falsy-string&numeric-string', sprintf('%2$14s', $mixed, $nonZeroIntRange));
6161

6262
assertType('numeric-string', sprintf('%2$.14F', $mixed, $i));
6363
assertType('numeric-string', sprintf('%2$.14F', $mixed, $f));

0 commit comments

Comments
 (0)