Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dedicated Type methods over isSuperTypeOf() #2788

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ private function processAssignVar(
new ObjectType(ArrayAccess::class),
new NullType(),
];
if ($offsetType !== null && (new IntegerType())->isSuperTypeOf($offsetType)->yes()) {
if ($offsetType !== null && $offsetType->isInteger()->yes()) {
$types[] = new StringType();
}
$offsetValueType = TypeCombinator::intersect($offsetValueType, TypeCombinator::union(...$types));
Expand All @@ -3911,7 +3911,7 @@ private function processAssignVar(
new ObjectType(ArrayAccess::class),
new NullType(),
];
if ($offsetNativeType !== null && (new IntegerType())->isSuperTypeOf($offsetNativeType)->yes()) {
if ($offsetNativeType !== null && $offsetNativeType->isInteger()->yes()) {
$types[] = new StringType();
}
$offsetNativeValueType = TypeCombinator::intersect($offsetNativeValueType, TypeCombinator::union(...$types));
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1507,8 +1507,8 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
}

if (
(new FloatType())->isSuperTypeOf($leftNumberType)->yes()
|| (new FloatType())->isSuperTypeOf($rightNumberType)->yes()
$leftNumberType->isFloat()->yes()
|| $rightNumberType->isFloat()->yes()
) {
return new FloatType();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/FunctionReturnTypeCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;
use PHPStan\Type\VoidType;
use function sprintf;

class FunctionReturnTypeCheck
Expand Down Expand Up @@ -53,7 +52,7 @@ public function checkReturnType(
}
}

$isVoidSuperType = (new VoidType())->isSuperTypeOf($returnType);
$isVoidSuperType = $returnType->isVoid();
$verbosityLevel = VerbosityLevel::getRecommendedLevelByType($returnType, null);
if ($returnValue === null) {
if (!$isVoidSuperType->no()) {
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Functions/ArrowFunctionReturnTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\VoidType;

/**
* @implements Rule<InArrowFunctionNode>
Expand Down Expand Up @@ -39,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
$generatorType = new ObjectType(Generator::class);

$originalNode = $node->getOriginalNode();
$isVoidSuperType = (new VoidType())->isSuperTypeOf($returnType);
$isVoidSuperType = $returnType->isVoid();
if ($originalNode->returnType === null && $isVoidSuperType->yes()) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/PhpDoc/InvalidThrowsPhpDocValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\ObjectType;
use PHPStan\Type\VerbosityLevel;
use PHPStan\Type\VoidType;
use Throwable;
use function sprintf;

Expand Down Expand Up @@ -57,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
}

$phpDocThrowsType = $resolvedPhpDoc->getThrowsTag()->getType();
if ((new VoidType())->isSuperTypeOf($phpDocThrowsType)->yes()) {
if ($phpDocThrowsType->isVoid()->yes()) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/MbStrlenFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getTypeFromFunctionCall(
} else {
$range = TypeCombinator::union(...array_map(static fn ($l) => new ConstantIntegerType($l), $lengths));
}
} elseif ((new BooleanType())->isSuperTypeOf($argType)->yes()) {
} elseif ($argType->isBoolean()->yes()) {
$range = IntegerRangeType::fromInterval(0, 1);
} elseif (
$isNonEmpty->yes()
Expand Down
6 changes: 2 additions & 4 deletions src/Type/Php/RangeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new IntegerType()));
}

$isFloat = (new FloatType())->isSuperTypeOf($argType)->yes();
if ($isFloat) {
if ($argType->isFloat()->yes()) {
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new FloatType()));
}

Expand All @@ -127,8 +126,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), $numberType));
}

$isString = $argType->isString()->yes();
if ($isString) {
if ($argType->isString()->yes()) {
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType()));
}

Expand Down