Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1599,12 +1599,6 @@ parameters:
count: 1
path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
Expand All @@ -1623,18 +1617,6 @@ parameters:
count: 1
path: src/Type/Php/ReflectionMethodConstructorThrowTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/Php/StrRepeatFunctionReturnTypeExtension.php

-
rawMessage: 'Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.'
identifier: phpstanApi.instanceofType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use function count;
use function in_array;

#[AutowiredService]
Expand All @@ -34,7 +34,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
$thousandsType = $scope->getType($functionCall->getArgs()[3]->value);
$decimalType = $scope->getType($functionCall->getArgs()[2]->value);

if (!$thousandsType instanceof ConstantStringType || $thousandsType->getValue() !== '') {
$constantThousandsTypes = $thousandsType->getConstantStrings();
if (count($constantThousandsTypes) !== 1 || $constantThousandsTypes[0]->getValue() !== '') {
return $stringType;
}

Expand Down
7 changes: 3 additions & 4 deletions src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\Accessory\AccessoryNonFalsyStringType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
Expand Down Expand Up @@ -42,11 +41,11 @@ public function getTypeFromFunctionCall(
return null;
}

$formatType = $scope->getType($args[1]->value);

if (!$formatType instanceof ConstantStringType) {
$formatType = $scope->getType($args[1]->value)->getConstantStrings();
if (count($formatType) !== 1) {
return null;
}
$formatType = $formatType[0];

if (preg_match_all('/%(\d*)(\[[^\]]+\]|[cdeEfosux]{1})/', $formatType->getValue(), $matches) > 0) {
$arrayBuilder = ConstantArrayTypeBuilder::createEmpty();
Expand Down
16 changes: 9 additions & 7 deletions src/Type/Php/StrRepeatFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public function getTypeFromFunctionCall(
}

$inputType = $scope->getType($args[0]->value);
if (
$inputType instanceof ConstantStringType
&& $multiplierType instanceof ConstantIntegerType
// don't generate type too big to avoid hitting memory limit
&& strlen($inputType->getValue()) * $multiplierType->getValue() < 100
) {
return new ConstantStringType(str_repeat($inputType->getValue(), $multiplierType->getValue()));
if ($multiplierType instanceof ConstantIntegerType) {
$constantInputStrings = $inputType->getConstantStrings();
if (
count($constantInputStrings) === 1
// don't generate type too big to avoid hitting memory limit
&& strlen($constantInputStrings[0]->getValue()) * $multiplierType->getValue() < 100
) {
return new ConstantStringType(str_repeat($constantInputStrings[0]->getValue(), $multiplierType->getValue()));
}
}

$accessoryTypes = [];
Expand Down
Loading