Skip to content

Commit 2048fc8

Browse files
committed
StrlenFunctionReturnTypeExtension: Cleanup instanceof ConstantStringType
1 parent 2132cc0 commit 2048fc8

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

phpstan-baseline.neon

-5
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,6 @@ parameters:
14881488
count: 1
14891489
path: src/Type/Php/StrRepeatFunctionReturnTypeExtension.php
14901490

1491-
-
1492-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
1493-
count: 1
1494-
path: src/Type/Php/StrlenFunctionReturnTypeExtension.php
1495-
14961491
-
14971492
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
14981493
count: 2

src/Type/Php/StrlenFunctionReturnTypeExtension.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\FunctionReflection;
88
use PHPStan\Type\BooleanType;
9-
use PHPStan\Type\Constant\ConstantBooleanType;
109
use PHPStan\Type\Constant\ConstantIntegerType;
11-
use PHPStan\Type\Constant\ConstantStringType;
1210
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1311
use PHPStan\Type\FloatType;
1412
use PHPStan\Type\IntegerRangeType;
@@ -44,25 +42,20 @@ public function getTypeFromFunctionCall(
4442
}
4543

4644
$argType = $scope->getType($args[0]->value);
47-
4845
if ($argType->isSuperTypeOf(new BooleanType())->yes()) {
49-
$constantScalars = TypeCombinator::remove($argType, new BooleanType())->getConstantScalarTypes();
46+
$constantScalars = TypeCombinator::remove($argType, new BooleanType())->getConstantScalarValues();
5047
if (count($constantScalars) > 0) {
51-
$constantScalars[] = new ConstantBooleanType(true);
52-
$constantScalars[] = new ConstantBooleanType(false);
48+
$constantScalars[] = true;
49+
$constantScalars[] = false;
5350
}
5451
} else {
55-
$constantScalars = $argType->getConstantScalarTypes();
52+
$constantScalars = $argType->getConstantScalarValues();
5653
}
5754

5855
$lengths = [];
5956
foreach ($constantScalars as $constantScalar) {
60-
$stringScalar = $constantScalar->toString();
61-
if (!($stringScalar instanceof ConstantStringType)) {
62-
$lengths = [];
63-
break;
64-
}
65-
$length = strlen($stringScalar->getValue());
57+
$stringScalar = (string) $constantScalar;
58+
$length = strlen($stringScalar);
6659
$lengths[] = $length;
6760
}
6861

0 commit comments

Comments
 (0)