Skip to content

Commit 14d5b98

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents bf923ad + dce063a commit 14d5b98

File tree

8 files changed

+9
-229
lines changed

8 files changed

+9
-229
lines changed

src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php

Lines changed: 4 additions & 0 deletions
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>
@@ -36,6 +37,9 @@ public function processNode(Node $node, Scope $scope): array
3637
}
3738

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

src/Type/Php/IsAFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 15 deletions
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
$scope,
6955
);

src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 15 deletions
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
$scope,
7056
);

tests/PHPStan/Analyser/TypeSpecifierTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,9 @@ public function dataCondition(): iterable
11341134
new Arg(new Variable('stringOrNull')),
11351135
new Arg(new Expr\ConstFetch(new Name('false'))),
11361136
]),
1137-
[],
1137+
[
1138+
'$object' => 'object',
1139+
],
11381140
[],
11391141
],
11401142
[

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -955,26 +955,4 @@ public function testAlwaysTruePregMatch(): void
955955
$this->analyse([__DIR__ . '/data/always-true-preg-match.php'], []);
956956
}
957957

958-
public function testBug3979(): void
959-
{
960-
$this->treatPhpDocTypesAsCertain = true;
961-
$this->analyse([__DIR__ . '/data/bug-3979.php'], []);
962-
}
963-
964-
public function testBug8464(): void
965-
{
966-
if (PHP_VERSION_ID < 80000) {
967-
$this->markTestSkipped('Test requires PHP 8.0.');
968-
}
969-
970-
$this->treatPhpDocTypesAsCertain = true;
971-
$this->analyse([__DIR__ . '/data/bug-8464.php'], []);
972-
}
973-
974-
public function testBug8954(): void
975-
{
976-
$this->treatPhpDocTypesAsCertain = true;
977-
$this->analyse([__DIR__ . '/data/bug-8954.php'], []);
978-
}
979-
980958
}

tests/PHPStan/Rules/Comparison/data/bug-3979.php

Lines changed: 0 additions & 130 deletions
This file was deleted.

tests/PHPStan/Rules/Comparison/data/bug-8464.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/PHPStan/Rules/Comparison/data/bug-8954.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)