Skip to content

Commit ea44c48

Browse files
authored
Cleanup instanceof ConstantStringType calls (#5753)
1 parent 94f5f76 commit ea44c48

3 files changed

Lines changed: 10 additions & 27 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,18 +1551,6 @@ parameters:
15511551
count: 1
15521552
path: src/Type/Php/CompactFunctionReturnTypeExtension.php
15531553

1554-
-
1555-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
1556-
identifier: phpstanApi.instanceofType
1557-
count: 1
1558-
path: src/Type/Php/DefineConstantTypeSpecifyingExtension.php
1559-
1560-
-
1561-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
1562-
identifier: phpstanApi.instanceofType
1563-
count: 1
1564-
path: src/Type/Php/DefinedConstantTypeSpecifyingExtension.php
1565-
15661554
-
15671555
rawMessage: 'Doing instanceof PHPStan\Type\TypeWithClassName is error-prone and deprecated. Use Type::getObjectClassNames() or Type::getObjectClassReflections() instead.'
15681556
identifier: phpstanApi.instanceofType

src/Type/Php/DefineConstantTypeSpecifyingExtension.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PHPStan\Analyser\TypeSpecifierContext;
1212
use PHPStan\DependencyInjection\AutowiredService;
1313
use PHPStan\Reflection\FunctionReflection;
14-
use PHPStan\Type\Constant\ConstantStringType;
1514
use PHPStan\Type\FunctionTypeSpecifyingExtension;
1615
use function count;
1716

@@ -45,23 +44,21 @@ public function specifyTypes(
4544
): SpecifiedTypes
4645
{
4746
$args = $node->getArgs();
48-
$constantName = $scope->getType($args[0]->value);
49-
if (
50-
!$constantName instanceof ConstantStringType
51-
|| $constantName->getValue() === ''
52-
) {
47+
$constantNames = $scope->getType($args[0]->value)->getConstantStrings();
48+
49+
if (count($constantNames) !== 1 || $constantNames[0]->getValue() === '') {
5350
return new SpecifiedTypes([], []);
5451
}
5552

5653
$valueType = $scope->getType($args[1]->value);
5754
$finalType = $scope->getConstantExplicitTypeFromConfig(
58-
$constantName->getValue(),
55+
$constantNames[0]->getValue(),
5956
$valueType,
6057
);
6158

6259
return $this->typeSpecifier->create(
6360
new Node\Expr\ConstFetch(
64-
new Node\Name\FullyQualified($constantName->getValue()),
61+
new Node\Name\FullyQualified($constantNames[0]->getValue()),
6562
),
6663
$finalType,
6764
TypeSpecifierContext::createTruthy(),

src/Type/Php/DefinedConstantTypeSpecifyingExtension.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Analyser\TypeSpecifierContext;
1111
use PHPStan\DependencyInjection\AutowiredService;
1212
use PHPStan\Reflection\FunctionReflection;
13-
use PHPStan\Type\Constant\ConstantStringType;
1413
use PHPStan\Type\FunctionTypeSpecifyingExtension;
1514
use PHPStan\Type\MixedType;
1615
use function count;
@@ -48,15 +47,14 @@ public function specifyTypes(
4847
TypeSpecifierContext $context,
4948
): SpecifiedTypes
5049
{
51-
$constantName = $scope->getType($node->getArgs()[0]->value);
52-
if (
53-
!$constantName instanceof ConstantStringType
54-
|| $constantName->getValue() === ''
55-
) {
50+
$args = $node->getArgs();
51+
$constantNames = $scope->getType($args[0]->value)->getConstantStrings();
52+
53+
if (count($constantNames) !== 1 || $constantNames[0]->getValue() === '') {
5654
return new SpecifiedTypes([], []);
5755
}
5856

59-
$expr = $this->constantHelper->createExprFromConstantName($constantName->getValue());
57+
$expr = $this->constantHelper->createExprFromConstantName($constantNames[0]->getValue());
6058
if ($expr === null) {
6159
return new SpecifiedTypes([], []);
6260
}

0 commit comments

Comments
 (0)