Skip to content

Commit dce063a

Browse files
committed
Revert "Fix ImpossibleCheckTypeFunctionCallRule for is_subclass_of and is_a"
This reverts commit 0711bec.
1 parent e6cd651 commit dce063a

6 files changed

+9
-168
lines changed

Diff for: src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleErrorBuilder;
1010
use function sprintf;
11+
use function strtolower;
1112

1213
/**
1314
* @implements Rule<Node\Expr\FuncCall>
@@ -37,6 +38,9 @@ public function processNode(Node $node, Scope $scope): array
3738
}
3839

3940
$functionName = (string) $node->name;
41+
if (strtolower($functionName) === 'is_a') {
42+
return [];
43+
}
4044
$isAlways = $this->impossibleCheckTypeHelper->findSpecifiedType($scope, $node);
4145
if ($isAlways === null) {
4246
return [];

Diff for: src/Type/Php/IsAFunctionTypeSpecifyingExtension.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
use PHPStan\Analyser\TypeSpecifierAwareExtension;
1010
use PHPStan\Analyser\TypeSpecifierContext;
1111
use PHPStan\Reflection\FunctionReflection;
12-
use PHPStan\Type\ClassStringType;
1312
use PHPStan\Type\Constant\ConstantBooleanType;
1413
use PHPStan\Type\Constant\ConstantStringType;
1514
use PHPStan\Type\FunctionTypeSpecifyingExtension;
16-
use PHPStan\Type\ObjectWithoutClassType;
17-
use PHPStan\Type\TypeCombinator;
1815
use function count;
1916
use function strtolower;
2017

@@ -50,20 +47,9 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
5047
$allowStringType = isset($node->getArgs()[2]) ? $scope->getType($node->getArgs()[2]->value) : new ConstantBooleanType(false);
5148
$allowString = !$allowStringType->equals(new ConstantBooleanType(false));
5249

53-
$superType = $allowString
54-
? TypeCombinator::union(new ObjectWithoutClassType(), new ClassStringType())
55-
: new ObjectWithoutClassType();
56-
57-
$resultType = $this->isAFunctionTypeSpecifyingHelper->determineType($objectOrClassType, $classType, $allowString, true);
58-
59-
// prevent false-positives in IsAFunctionTypeSpecifyingHelper
60-
if ($resultType->equals($superType) && $resultType->isSuperTypeOf($objectOrClassType)->yes()) {
61-
return new SpecifiedTypes([], []);
62-
}
63-
6450
return $this->typeSpecifier->create(
6551
$node->getArgs()[0]->value,
66-
$resultType,
52+
$this->isAFunctionTypeSpecifyingHelper->determineType($objectOrClassType, $classType, $allowString, true),
6753
$context,
6854
false,
6955
$scope,

Diff for: src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
use PHPStan\Analyser\TypeSpecifierAwareExtension;
1010
use PHPStan\Analyser\TypeSpecifierContext;
1111
use PHPStan\Reflection\FunctionReflection;
12-
use PHPStan\Type\ClassStringType;
1312
use PHPStan\Type\Constant\ConstantBooleanType;
1413
use PHPStan\Type\FunctionTypeSpecifyingExtension;
1514
use PHPStan\Type\Generic\GenericClassStringType;
16-
use PHPStan\Type\ObjectWithoutClassType;
17-
use PHPStan\Type\TypeCombinator;
1815
use function count;
1916
use function strtolower;
2017

@@ -51,20 +48,9 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
5148
return new SpecifiedTypes([], []);
5249
}
5350

54-
$superType = $allowString
55-
? TypeCombinator::union(new ObjectWithoutClassType(), new ClassStringType())
56-
: new ObjectWithoutClassType();
57-
58-
$resultType = $this->isAFunctionTypeSpecifyingHelper->determineType($objectOrClassType, $classType, $allowString, false);
59-
60-
// prevent false-positives in IsAFunctionTypeSpecifyingHelper
61-
if ($resultType->equals($superType) && $resultType->isSuperTypeOf($objectOrClassType)->yes()) {
62-
return new SpecifiedTypes([], []);
63-
}
64-
6551
return $this->typeSpecifier->create(
6652
$node->getArgs()[0]->value,
67-
$resultType,
53+
$this->isAFunctionTypeSpecifyingHelper->determineType($objectOrClassType, $classType, $allowString, false),
6854
$context,
6955
false,
7056
$scope,

Diff for: tests/PHPStan/Analyser/TypeSpecifierTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,9 @@ public function dataCondition(): iterable
11331133
new Arg(new Variable('stringOrNull')),
11341134
new Arg(new Expr\ConstFetch(new Name('false'))),
11351135
]),
1136-
[],
1136+
[
1137+
'$object' => 'object',
1138+
],
11371139
[],
11381140
],
11391141
[

Diff for: tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

-7
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,4 @@ public function testAlwaysTruePregMatch(): void
11021102
$this->analyse([__DIR__ . '/data/always-true-preg-match.php'], []);
11031103
}
11041104

1105-
public function testBug3979(): void
1106-
{
1107-
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
1108-
$this->treatPhpDocTypesAsCertain = true;
1109-
$this->analyse([__DIR__ . '/data/bug-3979.php'], []);
1110-
}
1111-
11121105
}

Diff for: tests/PHPStan/Rules/Comparison/data/bug-3979.php

-130
This file was deleted.

0 commit comments

Comments
 (0)