Skip to content

Commit e9008e6

Browse files
herndlmondrejmirtes
authored andcommitted
Use isArray instead of array supertype checks
1 parent 3dffa19 commit e9008e6

4 files changed

+4
-10
lines changed

src/Reflection/InitializerExprTypeResolver.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,7 @@ public function getPlusType(Expr $left, Expr $right, callable $getTypeCallback):
927927
return TypeCombinator::union(...$resultTypes);
928928
}
929929

930-
$arrayType = new ArrayType(new MixedType(), new MixedType());
931-
932-
if ($arrayType->isSuperTypeOf($leftType)->yes() && $arrayType->isSuperTypeOf($rightType)->yes()) {
930+
if ($leftType->isArray()->yes() && $rightType->isArray()->yes()) {
933931
if ($leftType->getIterableKeyType()->equals($rightType->getIterableKeyType())) {
934932
// to preserve BenevolentUnionType
935933
$keyType = $leftType->getIterableKeyType();

src/Type/Php/CountFunctionTypeSpecifyingExtension.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
use PHPStan\Analyser\TypeSpecifierContext;
1111
use PHPStan\Reflection\FunctionReflection;
1212
use PHPStan\Type\Accessory\NonEmptyArrayType;
13-
use PHPStan\Type\ArrayType;
1413
use PHPStan\Type\FunctionTypeSpecifyingExtension;
15-
use PHPStan\Type\MixedType;
1614
use function count;
1715
use function in_array;
1816

@@ -39,7 +37,7 @@ public function specifyTypes(
3937
TypeSpecifierContext $context,
4038
): SpecifiedTypes
4139
{
42-
if (!(new ArrayType(new MixedType(), new MixedType()))->isSuperTypeOf($scope->getType($node->getArgs()[0]->value))->yes()) {
40+
if (!$scope->getType($node->getArgs()[0]->value)->isArray()->yes()) {
4341
return new SpecifiedTypes([], []);
4442
}
4543

src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Type\ArrayType;
1010
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1111
use PHPStan\Type\IntegerType;
12-
use PHPStan\Type\MixedType;
1312
use PHPStan\Type\StringType;
1413
use PHPStan\Type\Type;
1514

@@ -34,7 +33,7 @@ public function getTypeFromFunctionCall(
3433

3534
$argType = $scope->getType($functionCall->getArgs()[0]->value);
3635
$isString = (new StringType())->isSuperTypeOf($argType);
37-
$isArray = (new ArrayType(new MixedType(), new MixedType()))->isSuperTypeOf($argType);
36+
$isArray = $argType->isArray();
3837
$compare = $isString->compareTo($isArray);
3938
if ($compare === $isString) {
4039
return new StringType();

src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
9191
}
9292

9393
$stringType = new StringType();
94-
$arrayType = new ArrayType(new MixedType(), new MixedType());
9594

9695
$isStringSuperType = $stringType->isSuperTypeOf($subjectArgumentType);
97-
$isArraySuperType = $arrayType->isSuperTypeOf($subjectArgumentType);
96+
$isArraySuperType = $subjectArgumentType->isArray();
9897
$compareSuperTypes = $isStringSuperType->compareTo($isArraySuperType);
9998
if ($compareSuperTypes === $isStringSuperType) {
10099
return $stringType;

0 commit comments

Comments
 (0)