diff --git a/rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php b/rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php index b8fdb1be397..246b3a71996 100644 --- a/rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php @@ -16,7 +16,6 @@ use PhpParser\NodeTraverser; use PHPStan\Type\NullType; use PHPStan\Type\UnionType; -use PHPStan\Type\VoidType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; @@ -157,7 +156,7 @@ private function transformDocUnionVoidToUnionNull(ClassMethod|Function_ $node): $newTypes = []; $hasChanged = false; foreach ($returnType->getTypes() as $type) { - if ($type instanceof VoidType) { + if ($type->isVoid()->yes()) { $type = new NullType(); $hasChanged = true; } diff --git a/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php index 559c748f5ea..6e34d6f6142 100644 --- a/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php +++ b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php @@ -18,8 +18,8 @@ use PhpParser\Node\Stmt\Property; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; -use PHPStan\Type\ArrayType; use PHPStan\Type\MixedType; +use PHPStan\Type\Type; use Rector\NodeAnalyzer\ExprAnalyzer; use Rector\Php\ReservedKeywordAnalyzer; use Rector\PhpParser\AstResolver; @@ -104,7 +104,7 @@ private function isAllowedVariable(Variable $variable): bool private function isAllowedExpr(Expr $expr, Scope $scope): bool { - if (! $scope->getType($expr) instanceof ArrayType) { + if (! $scope->getType($expr)->isArray()->yes()) { return false; } @@ -134,7 +134,8 @@ private function isAllowedExpr(Expr $expr, Scope $scope): bool $nativeType = $phpPropertyReflection->getNativeType(); if (! $nativeType instanceof MixedType) { - return $nativeType instanceof ArrayType; + return $nativeType->isArray() + ->yes(); } $property = $this->astResolver->resolvePropertyFromPropertyReflection($phpPropertyReflection); @@ -150,6 +151,11 @@ private function isAllowedExpr(Expr $expr, Scope $scope): bool } $type = $this->allAssignNodePropertyTypeInferer->inferProperty($property, $classReflection, $this->file); - return $type instanceof ArrayType; + if (! $type instanceof Type) { + return false; + } + + return $type->isArray() + ->yes(); } } diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfNullableReturnRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfNullableReturnRector.php index 13878dab6a4..03767341002 100644 --- a/rules/CodeQuality/Rector/If_/SimplifyIfNullableReturnRector.php +++ b/rules/CodeQuality/Rector/If_/SimplifyIfNullableReturnRector.php @@ -14,7 +14,6 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Return_; -use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; @@ -225,11 +224,11 @@ private function processSimplifyNullableReturn( return null; } - if ($types[0] instanceof FullyQualifiedObjectType && $types[1] instanceof NullType && $className === $types[0]->getClassName()) { + if ($types[0] instanceof FullyQualifiedObjectType && $types[1]->isNull()->yes() && $className === $types[0]->getClassName()) { return $this->createDirectReturn($expression, $expr, $unionType); } - if ($types[0] instanceof NullType && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) { + if ($types[0]->isNull()->yes() && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) { return $this->createDirectReturn($expression, $expr, $unionType); } @@ -249,7 +248,7 @@ private function isNotTypedNullable(array $types, string $className): bool return true; } - if (! $types[1] instanceof NullType) { + if (! $types[1]->isNull()->yes()) { return true; } diff --git a/rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php b/rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php index 35bf3cace44..e1a24f6c0b0 100644 --- a/rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php +++ b/rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\BooleanOr; use PhpParser\Node\Stmt\If_; -use PHPStan\Type\Constant\ConstantBooleanType; use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -79,11 +78,7 @@ public function refactor(Node $node): ?Node $booleanOr = $node->cond; $conditionStaticType = $this->getType($booleanOr->left); - if (! $conditionStaticType instanceof ConstantBooleanType) { - return null; - } - - if ($conditionStaticType->getValue()) { + if (! $conditionStaticType->isFalse()->yes()) { return null; } diff --git a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php index e64c11fab95..7d2866981b3 100644 --- a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php +++ b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php @@ -18,8 +18,6 @@ use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; use PhpParser\NodeTraverser; -use PHPStan\Type\ArrayType; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\IntersectionType; use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer; use Rector\NodeAnalyzer\ExprAnalyzer; @@ -101,11 +99,7 @@ public function refactor(Node $node): int|null|array|If_ } $conditionStaticType = $this->getType($node->cond); - if (! $conditionStaticType instanceof ConstantBooleanType) { - return null; - } - - if (! $conditionStaticType->getValue()) { + if (! $conditionStaticType->isTrue()->yes()) { return null; } @@ -142,7 +136,7 @@ private function shouldSkipFromVariable(Expr $expr): bool $type = $this->getType($variable); if ($type instanceof IntersectionType) { foreach ($type->getTypes() as $subType) { - if ($subType instanceof ArrayType) { + if ($subType->isArray()->yes()) { return true; } } @@ -175,11 +169,7 @@ private function refactorIfWithBooleanAnd(If_ $if): ?If_ $booleanAnd = $if->cond; $leftType = $this->getType($booleanAnd->left); - if (! $leftType instanceof ConstantBooleanType) { - return null; - } - - if (! $leftType->getValue()) { + if (! $leftType->isTrue()->yes()) { return null; } diff --git a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php index d7e1aeead17..80dffd208e9 100644 --- a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php +++ b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php @@ -21,7 +21,6 @@ use PhpParser\Node\Stmt\While_; use PhpParser\NodeTraverser; use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\ConstantType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; @@ -153,7 +152,7 @@ function (Node $subNode): null|int|Break_ { private function processVariableNum(Continue_ $continue, Variable $numVariable): Continue_ | Break_ { $staticType = $this->getType($numVariable); - if (! $staticType instanceof ConstantType) { + if (! $staticType->isConstantValue()->yes()) { return $continue; } diff --git a/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php b/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php index da4357f92aa..551f1518555 100644 --- a/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php +++ b/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php @@ -11,7 +11,6 @@ use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Continue_; use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\ConstantType; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; @@ -115,7 +114,7 @@ private function processVariableNum(Break_ | Continue_ $stmt, Variable $numVaria { $staticType = $this->getType($numVariable); - if ($staticType instanceof ConstantType) { + if ($staticType->isConstantValue()->yes()) { if ($staticType instanceof ConstantIntegerType) { if ($staticType->getValue() === 0) { $stmt->num = null; diff --git a/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php b/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php index 69b17e25d11..7a49f87ebb5 100644 --- a/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php +++ b/rules/Php72/Rector/FuncCall/GetClassOnNullRector.php @@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\NodeTraverser; use PHPStan\Analyser\Scope; -use PHPStan\Type\NullType; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractScopeAwareRector; use Rector\ValueObject\PhpVersionFeature; @@ -104,7 +103,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node $firstArgValue = $firstArg->value; $firstArgType = $this->getType($firstArgValue); - if (! $this->nodeTypeResolver->isNullableType($firstArgValue) && ! $firstArgType instanceof NullType) { + if (! $this->nodeTypeResolver->isNullableType($firstArgValue) && ! $firstArgType->isNull()->yes()) { return null; } diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index 82cbcd94b46..6dbf7ebdd06 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -22,7 +22,6 @@ use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Type\ErrorType; use PHPStan\Type\MixedType; -use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\NodeAnalyzer\ArgsAnalyzer; @@ -263,7 +262,7 @@ private function isValidUnionType(Type $type): bool private function shouldSkipType(Type $type): bool { return ! $type instanceof MixedType && - ! $type instanceof NullType && + ! $type->isNull()->yes() && ! $this->isValidUnionType($type); } diff --git a/rules/Strict/NodeFactory/ExactCompareFactory.php b/rules/Strict/NodeFactory/ExactCompareFactory.php index 751ea4055dc..992b86bc01c 100644 --- a/rules/Strict/NodeFactory/ExactCompareFactory.php +++ b/rules/Strict/NodeFactory/ExactCompareFactory.php @@ -21,7 +21,6 @@ use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; -use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeWithClassName; @@ -55,7 +54,7 @@ public function createIdenticalFalsyCompare( return new Identical($expr, $this->nodeFactory->createFalse()); } elseif ($exprType->isArray()->yes()) { return new Identical($expr, new Array_([])); - } elseif ($exprType instanceof NullType) { + } elseif ($exprType->isNull()->yes()) { return new Identical($expr, $this->nodeFactory->createNull()); } elseif (! $exprType instanceof UnionType) { return null; diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php index af4ceb2801a..40c77cead07 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php @@ -10,7 +10,6 @@ use PhpParser\Node\Identifier; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; -use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\ThisType; use PHPStan\Type\Type; @@ -108,7 +107,7 @@ private function unionToSingleType(array $staticTypesByArgumentPosition): array return $staticTypeByArgumentPosition; } - if (! $staticTypeByArgumentPosition[0] instanceof NullType) { + if (! $staticTypeByArgumentPosition[0]->isNull()->yes()) { return $staticTypeByArgumentPosition; } diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php index a4c14a7f6ee..a7dae96a530 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php @@ -22,7 +22,6 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\MixedType; -use PHPStan\Type\NullType; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\PhpParser\AstResolver; @@ -71,7 +70,7 @@ public function matchCallParamType( return $callParam->type; } - if (! $defaultType instanceof NullType) { + if (! $defaultType->isNull()->yes()) { return null; } diff --git a/rules/TypeDeclaration/NodeAnalyzer/ClassMethodParamTypeCompleter.php b/rules/TypeDeclaration/NodeAnalyzer/ClassMethodParamTypeCompleter.php index b3b21a970e0..2efac4ae983 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ClassMethodParamTypeCompleter.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ClassMethodParamTypeCompleter.php @@ -9,7 +9,6 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; -use PHPStan\Type\CallableType; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -126,11 +125,11 @@ private function shouldSkipArgumentStaticType( private function isClosureAndCallableType(Type $parameterStaticType, Type $argumentStaticType): bool { - if ($parameterStaticType instanceof CallableType && $this->isClosureObjectType($argumentStaticType)) { + if ($parameterStaticType->isCallable()->yes() && $this->isClosureObjectType($argumentStaticType)) { return true; } - return $argumentStaticType instanceof CallableType && $this->isClosureObjectType($parameterStaticType); + return $argumentStaticType->isCallable()->yes() && $this->isClosureObjectType($parameterStaticType); } private function isClosureObjectType(Type $type): bool diff --git a/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php b/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php index 6a705c91ba9..b0e8156881c 100644 --- a/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php +++ b/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php @@ -25,7 +25,6 @@ use PHPStan\Type\IntegerType; use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; -use PHPStan\Type\NullType; use PHPStan\Type\ObjectWithoutClassType; use PHPStan\Type\StringType; use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareIntersectionTypeNode; @@ -49,7 +48,7 @@ public function resolveTypeExpressionFromVarTag(TypeNode $typeNode, Variable $va return new FuncCall(new Name($scalarTypeFunction), [$arg]); } - if ($scalarType instanceof NullType) { + if ($scalarType->isNull()->yes()) { return new Identical($variable, new ConstFetch(new Name('null'))); } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromBooleanStrictReturnsRector.php b/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromBooleanStrictReturnsRector.php index 9918a96cc81..092751fa9fd 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromBooleanStrictReturnsRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromBooleanStrictReturnsRector.php @@ -29,7 +29,6 @@ use PhpParser\Node\Stmt\Return_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; -use PHPStan\Type\BooleanType; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractScopeAwareRector; @@ -181,10 +180,12 @@ private function isNativeBooleanReturnTypeFuncCall(FuncCall $funcCall): bool } foreach ($functionReflection->getVariants() as $parametersAcceptorWithPhpDoc) { - return $parametersAcceptorWithPhpDoc->getNativeReturnType() instanceof BooleanType; + if (! $parametersAcceptorWithPhpDoc->getNativeReturnType()->isBoolean()->yes()) { + return false; + } } - return false; + return true; } private function isBooleanOp(Expr $expr): bool diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php index 7b588a5720e..61c8c2bfaba 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php @@ -16,7 +16,6 @@ use PhpParser\Node\Stmt\Return_; use PhpParser\Node\UnionType as PhpParserUnionType; use PHPStan\Analyser\Scope; -use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\UnionType; use Rector\Php\PhpVersionProvider; @@ -175,7 +174,7 @@ private function processSingleUnionType( NullableType $nullableType ): Closure | ClassMethod | Function_ { $types = $unionType->getTypes(); - $returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType + $returnType = $types[0] instanceof ObjectType && $types[1]->isNull()->yes() ? new NullableType(new FullyQualified($types[0]->getClassName())) : $nullableType; diff --git a/rules/TypeDeclaration/TypeAnalyzer/PropertyTypeDefaultValueAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/PropertyTypeDefaultValueAnalyzer.php index 8f5a366f66b..2404aa10923 100644 --- a/rules/TypeDeclaration/TypeAnalyzer/PropertyTypeDefaultValueAnalyzer.php +++ b/rules/TypeDeclaration/TypeAnalyzer/PropertyTypeDefaultValueAnalyzer.php @@ -6,7 +6,6 @@ use PhpParser\Node\Expr; use PhpParser\Node\Stmt\PropertyProperty; -use PHPStan\Type\ArrayType; use PHPStan\Type\Type; use Rector\StaticTypeMapper\StaticTypeMapper; @@ -25,7 +24,7 @@ public function doesConflictWithDefaultValue(PropertyProperty $propertyProperty, // the defaults can be in conflict $defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($propertyProperty->default); - if ($defaultType instanceof ArrayType && $propertyType instanceof ArrayType) { + if ($defaultType->isArray()->yes() && $propertyType->isArray()->yes()) { return false; } diff --git a/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php b/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php index 7926c930bb2..52f4bc64239 100644 --- a/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php @@ -189,7 +189,7 @@ private function isParamNullable(Param $param): bool if ($param->default instanceof Expr) { $defaultValueStaticType = $this->nodeTypeResolver->getType($param->default); - if ($defaultValueStaticType instanceof NullType) { + if ($defaultValueStaticType->isNull()->yes()) { return true; } } diff --git a/src/NodeAnalyzer/PropertyAnalyzer.php b/src/NodeAnalyzer/PropertyAnalyzer.php index bd1c61bbd6a..f376fbc0924 100644 --- a/src/NodeAnalyzer/PropertyAnalyzer.php +++ b/src/NodeAnalyzer/PropertyAnalyzer.php @@ -5,8 +5,6 @@ namespace Rector\NodeAnalyzer; use PhpParser\Node\Stmt\Property; -use PHPStan\Type\CallableType; -use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; use PHPStan\Type\UnionType; @@ -23,7 +21,7 @@ public function __construct( public function hasForbiddenType(Property $property): bool { $propertyType = $this->nodeTypeResolver->getType($property); - if ($propertyType instanceof NullType) { + if ($propertyType->isNull()->yes()) { return true; } @@ -60,6 +58,6 @@ private function isCallableType(Type $type): bool return false; } - return $type instanceof CallableType; + return $type->isCallable()->yes(); } } diff --git a/src/NodeTypeResolver/NodeTypeResolver.php b/src/NodeTypeResolver/NodeTypeResolver.php index c4839d03d29..390c5d231ca 100644 --- a/src/NodeTypeResolver/NodeTypeResolver.php +++ b/src/NodeTypeResolver/NodeTypeResolver.php @@ -431,7 +431,7 @@ private function isAnonymousObjectType(Type $type): bool private function isUnionTypeable(Type $first, Type $second): bool { - return ! $first instanceof UnionType && ! $second instanceof UnionType && ! $second instanceof NullType; + return ! $first instanceof UnionType && ! $second instanceof UnionType && ! $second->isNull()->yes(); } private function isMatchingUnionType(Type $resolvedType, ObjectType $requiredObjectType): bool diff --git a/src/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php b/src/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php index 609ce65e62d..dee517e5691 100644 --- a/src/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php +++ b/src/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php @@ -8,7 +8,6 @@ use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\ConstantScalarType; use PHPStan\Type\MixedType; -use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; @@ -44,7 +43,7 @@ public function isAlwaysTruableType(Type $type): bool return true; } - if ($type instanceof ConstantScalarType && ! $type instanceof NullType) { + if ($type instanceof ConstantScalarType && ! $type->isNull()->yes()) { return (bool) $type->getValue(); } diff --git a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php index 5a1bff28261..46179fa92aa 100644 --- a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php +++ b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php @@ -7,7 +7,6 @@ use PHPStan\Type\ArrayType; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; @@ -104,17 +103,15 @@ private function normalizeObjectType(int $totalTypes, Type $type): Type private function normalizeBooleanType(bool &$hasFalse, bool &$hasTrue, Type $type): Type { - if ($type instanceof ConstantBooleanType) { - if ($type->getValue()) { - $hasTrue = true; - } + if ($type->isTrue()->yes()) { + $hasTrue = true; + } - if ($type->getValue() === false) { - $hasFalse = true; - } + if ($type->isFalse()->yes()) { + $hasFalse = true; } - if ($hasFalse && $hasTrue && $type instanceof ConstantBooleanType) { + if ($hasFalse && $hasTrue && ($type->isTrue()->yes() || $type->isFalse()->yes())) { return new BooleanType(); } @@ -185,7 +182,7 @@ private function removeValueFromConstantType(Type $type): Type return new IntegerType(); } - if ($type instanceof ConstantBooleanType) { + if ($type->isTrue()->yes() || $type->isFalse()->yes()) { return new BooleanType(); } diff --git a/src/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php b/src/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php index d9dc76ab2b3..e2062368eda 100644 --- a/src/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php +++ b/src/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php @@ -4,7 +4,6 @@ namespace Rector\NodeTypeResolver\TypeComparator; -use PHPStan\Type\ClassStringType; use PHPStan\Type\Type; /** @@ -68,7 +67,7 @@ public function areDifferentScalarTypes(Type $firstType, Type $secondType): bool return $firstType::class !== $secondType::class; } - if (! $secondType instanceof ClassStringType) { + if (! $secondType->isClassStringType()->yes()) { return $firstType::class !== $secondType::class; } diff --git a/src/NodeTypeResolver/TypeComparator/TypeComparator.php b/src/NodeTypeResolver/TypeComparator/TypeComparator.php index b75ac482818..7116bfbd7c1 100644 --- a/src/NodeTypeResolver/TypeComparator/TypeComparator.php +++ b/src/NodeTypeResolver/TypeComparator/TypeComparator.php @@ -9,7 +9,6 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Type\ArrayType; use PHPStan\Type\BooleanType; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\ConstantScalarType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\MixedType; @@ -197,7 +196,7 @@ private function isMutualObjectSubtypes(Type $firstArrayItemType, Type $secondAr private function normalizeConstantBooleanType(Type $type): Type { return TypeTraverser::map($type, static function (Type $type, callable $callable): Type { - if ($type instanceof ConstantBooleanType) { + if ($type->isTrue()->yes() || $type->isFalse()->yes()) { return new BooleanType(); } diff --git a/src/PHPStanStaticTypeMapper/DoctrineTypeAnalyzer.php b/src/PHPStanStaticTypeMapper/DoctrineTypeAnalyzer.php index 03c67a4a40b..05478716588 100644 --- a/src/PHPStanStaticTypeMapper/DoctrineTypeAnalyzer.php +++ b/src/PHPStanStaticTypeMapper/DoctrineTypeAnalyzer.php @@ -4,7 +4,6 @@ namespace Rector\PHPStanStaticTypeMapper; -use PHPStan\Type\ArrayType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; @@ -17,15 +16,15 @@ public function isDoctrineCollectionWithIterableUnionType(Type $type): bool return false; } - $arrayType = null; + $isArrayType = false; $hasDoctrineCollectionType = false; foreach ($type->getTypes() as $unionedType) { if ($this->isInstanceOfCollectionType($unionedType)) { $hasDoctrineCollectionType = true; } - if ($unionedType instanceof ArrayType) { - $arrayType = $unionedType; + if ($unionedType->isArray()->yes()) { + $isArrayType = true; } } @@ -33,7 +32,7 @@ public function isDoctrineCollectionWithIterableUnionType(Type $type): bool return false; } - return $arrayType instanceof ArrayType; + return $isArrayType; } public function isInstanceOfCollectionType(Type $type): bool diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php index 1257de24e76..0370fb50a24 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php @@ -205,7 +205,7 @@ private function isIntegerKeyAndNonNestedArray(ArrayType $arrayType): bool return false; } - return ! $arrayType->getItemType() instanceof ArrayType; + return ! $arrayType->getItemType()->isArray()->yes(); } private function isClassStringArrayType(ArrayType $arrayType): bool diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php index fa3f1711427..2c380e04ab4 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php @@ -8,7 +8,6 @@ use PhpParser\Node\Identifier; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\BooleanType; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Type; use Rector\Php\PhpVersionProvider; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -51,14 +50,20 @@ public function mapToPhpParserNode(Type $type, string $typeKind): ?Node return new Identifier('bool'); } - if ($typeKind === TypeKind::UNION && $type instanceof ConstantBooleanType && $type->getValue() === false) { + if ($typeKind === TypeKind::UNION && $type->isFalse()->yes()) { return new Identifier('false'); } - if ($this->phpVersionProvider->isAtLeastPhpVersion( - PhpVersionFeature::NULL_FALSE_TRUE_STANDALONE_TYPE - ) && $type instanceof ConstantBooleanType) { - return $type->getValue() ? new Identifier('true') : new Identifier('false'); + if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NULL_FALSE_TRUE_STANDALONE_TYPE)) { + return new Identifier('bool'); + } + + if ($type->isTrue()->yes()) { + return new Identifier('true'); + } + + if ($type->isFalse()->yes()) { + return new Identifier('false'); } return new Identifier('bool'); diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php index 6bc54256275..3248ca7b828 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php @@ -13,7 +13,6 @@ use PhpParser\Node\NullableType; use PhpParser\Node\UnionType as PhpParserUnionType; use PHPStan\PhpDocParser\Ast\Type\TypeNode; -use PHPStan\Type\CallableType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode; @@ -185,7 +184,7 @@ private function matchPhpParserUnionType(UnionType $unionType, string $typeKind) } // special callable type only not allowed on property - if ($typeKind === TypeKind::PROPERTY && $unionedType instanceof CallableType) { + if ($typeKind === TypeKind::PROPERTY && $unionedType->isCallable()->yes()) { return null; } diff --git a/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php b/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php index 0f56838f4ca..f9244bd0feb 100644 --- a/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php +++ b/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php @@ -4,7 +4,6 @@ namespace Rector\PHPStanStaticTypeMapper\Utils; -use PHPStan\Type\CallableType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeWithClassName; @@ -29,14 +28,14 @@ public function unwrapFirstObjectTypeFromUnionType(Type $type): Type return $type; } - public function unwrapFirstCallableTypeFromUnionType(Type $type): ?Type + public function unwrapFirstCallableTypeFromUnionType(Type $type): Type { if (! $type instanceof UnionType) { return $type; } foreach ($type->getTypes() as $unionedType) { - if (! $unionedType instanceof CallableType) { + if (! $unionedType->isCallable()->yes()) { continue; } diff --git a/src/PhpAttribute/NodeFactory/AnnotationToAttributeIntegerValueCaster.php b/src/PhpAttribute/NodeFactory/AnnotationToAttributeIntegerValueCaster.php index 62bee811217..a334125a55a 100644 --- a/src/PhpAttribute/NodeFactory/AnnotationToAttributeIntegerValueCaster.php +++ b/src/PhpAttribute/NodeFactory/AnnotationToAttributeIntegerValueCaster.php @@ -12,7 +12,6 @@ use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ReflectionProvider; -use PHPStan\Type\IntegerType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\Php80\ValueObject\AnnotationToAttribute; @@ -80,7 +79,7 @@ public function castAttributeTypes(AnnotationToAttribute $annotationToAttribute, private function containsInteger(Type $type): bool { - if ($type instanceof IntegerType) { + if ($type->isInteger()->yes()) { return true; } @@ -89,7 +88,7 @@ private function containsInteger(Type $type): bool } foreach ($type->getTypes() as $unionedType) { - if ($unionedType instanceof IntegerType) { + if ($unionedType->isInteger()->yes()) { return true; } }