Skip to content

Commit 40ba340

Browse files
committed
remove redundant check for object being a constant string
1 parent 1f40e18 commit 40ba340

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,12 +1647,6 @@ parameters:
16471647
count: 1
16481648
path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php
16491649

1650-
-
1651-
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantStringType is error\-prone and deprecated\. Use Type\:\:getConstantStrings\(\) instead\.$#'
1652-
identifier: phpstanApi.instanceofType
1653-
count: 1
1654-
path: src/Type/Php/PropertyExistsTypeSpecifyingExtension.php
1655-
16561650
-
16571651
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantStringType is error\-prone and deprecated\. Use Type\:\:getConstantStrings\(\) instead\.$#'
16581652
identifier: phpstanApi.instanceofType

src/Type/Php/PropertyExistsTypeSpecifyingExtension.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPStan\Rules\Properties\PropertyReflectionFinder;
1717
use PHPStan\Type\Accessory\HasPropertyType;
1818
use PHPStan\Type\Constant\ConstantBooleanType;
19-
use PHPStan\Type\Constant\ConstantStringType;
2019
use PHPStan\Type\FunctionTypeSpecifyingExtension;
2120
use PHPStan\Type\IntersectionType;
2221
use PHPStan\Type\ObjectWithoutClassType;
@@ -72,23 +71,22 @@ public function specifyTypes(
7271
}
7372

7473
$objectType = $scope->getType($node->getArgs()[0]->value);
75-
if ($objectType instanceof ConstantStringType) {
74+
75+
if (!$objectType->isObject()->yes()) {
7676
return new SpecifiedTypes([], []);
77-
} elseif ($objectType->isObject()->yes()) {
78-
$propertyNodes = [];
79-
80-
foreach ($propertyNameTypes as $propertyNameType) {
81-
if ($propertyNameType->getValue() === '') {
82-
return new SpecifiedTypes([], []);
83-
}
84-
85-
$propertyNodes[] = new PropertyFetch(
86-
$node->getArgs()[0]->value,
87-
new Identifier($propertyNameType->getValue()),
88-
);
77+
}
78+
79+
$propertyNodes = [];
80+
81+
foreach ($propertyNameTypes as $propertyNameType) {
82+
if ($propertyNameType->getValue() === '') {
83+
return new SpecifiedTypes([], []);
8984
}
90-
} else {
91-
return new SpecifiedTypes([], []);
85+
86+
$propertyNodes[] = new PropertyFetch(
87+
$node->getArgs()[0]->value,
88+
new Identifier($propertyNameType->getValue()),
89+
);
9290
}
9391

9492
foreach ($propertyNodes as $propertyNode) {

0 commit comments

Comments
 (0)