Skip to content

Commit

Permalink
Keep numeric-strings in str_repeat()
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 13, 2024
1 parent 031b344 commit ef7d199
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Type/Php/StrRepeatFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
use PHPStan\Type\Accessory\AccessoryNonFalsyStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
Expand Down Expand Up @@ -74,6 +75,10 @@ public function getTypeFromFunctionCall(
$accessoryTypes[] = new AccessoryLiteralStringType();
}

if ($inputType->isNumericString()->yes()) {
$accessoryTypes[] = new AccessoryNumericStringType();
}

if (count($accessoryTypes) > 0) {
$accessoryTypes[] = new StringType();
return new IntersectionType($accessoryTypes);
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/data/literal-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function doFoo($literalString, string $string)
str_repeat('a', 99)
);
assertType('literal-string&non-falsy-string', str_repeat('a', 100));
assertType('literal-string&non-empty-string&numeric-string', str_repeat('0', 100));
assertType('literal-string&non-falsy-string&numeric-string', str_repeat('1', 100));
assertType("'?,?,?,'", str_repeat('?,', 3));
assertType("*NEVER*", str_repeat('?,', -3));

Expand Down

0 comments on commit ef7d199

Please sign in to comment.