diff --git a/packages/NodeTypeResolver/NodeTypeResolver.php b/packages/NodeTypeResolver/NodeTypeResolver.php index e947450fbf0..274b1264598 100644 --- a/packages/NodeTypeResolver/NodeTypeResolver.php +++ b/packages/NodeTypeResolver/NodeTypeResolver.php @@ -23,6 +23,8 @@ use PHPStan\Broker\ClassAutoloadingException; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\Constant\ConstantBooleanType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; @@ -240,10 +242,10 @@ final class NodeTypeResolver public function isNumberType(Expr $expr) : bool { $nodeType = $this->getType($expr); - if ($nodeType->isInteger()->yes()) { + if ($nodeType instanceof IntegerType) { return \true; } - return $nodeType->isFloat()->yes(); + return $nodeType instanceof FloatType; } /** * @api diff --git a/packages/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php b/packages/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php index 3e8ae0c19ba..2965632de92 100644 --- a/packages/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php +++ b/packages/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php @@ -4,8 +4,11 @@ declare (strict_types=1); namespace Rector\NodeTypeResolver\PHPStan\Type; use PHPStan\Type\ArrayType; +use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\ConstantScalarType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; @@ -54,16 +57,16 @@ final class StaticTypeAnalyzer if ($type instanceof NullType) { return \true; } - if ($type->isBoolean()->yes()) { + if ($type instanceof BooleanType) { return \true; } if ($type->isString()->yes()) { return \true; } - if ($type->isInteger()->yes()) { + if ($type instanceof IntegerType) { return \true; } - return $type->isFloat()->yes(); + return $type instanceof FloatType; } private function isAlwaysTruableUnionType(Type $type) : bool { diff --git a/packages/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php b/packages/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php index dd2561c0e3b..c23c852444d 100644 --- a/packages/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php +++ b/packages/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php @@ -3,7 +3,11 @@ declare (strict_types=1); namespace Rector\NodeTypeResolver\TypeComparator; +use PHPStan\Type\BooleanType; use PHPStan\Type\ClassStringType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; +use PHPStan\Type\StringType; use PHPStan\Type\Type; /** * @see \Rector\Tests\NodeTypeResolver\TypeComparator\ScalarTypeComparatorTest @@ -12,22 +16,22 @@ final class ScalarTypeComparator { public function areEqualScalar(Type $firstType, Type $secondType) : bool { - if ($firstType->isString()->yes() && $secondType->isString()->yes()) { + if ($firstType instanceof StringType && $secondType instanceof StringType) { // prevents "class-string" vs "string" $firstTypeClass = \get_class($firstType); $secondTypeClass = \get_class($secondType); return $firstTypeClass === $secondTypeClass; } - if ($firstType->isInteger()->yes() && $secondType->isInteger()->yes()) { + if ($firstType instanceof IntegerType && $secondType instanceof IntegerType) { return \true; } - if ($firstType->isFloat()->yes() && $secondType->isFloat()->yes()) { + if ($firstType instanceof FloatType && $secondType instanceof FloatType) { return \true; } - if (!$firstType->isBoolean()->yes()) { + if (!$firstType instanceof BooleanType) { return \false; } - return $secondType->isBoolean()->yes(); + return $secondType instanceof BooleanType; } /** * E.g. first is string, second is bool @@ -41,10 +45,10 @@ final class ScalarTypeComparator return \false; } // treat class-string and string the same - if ($firstType instanceof ClassStringType && $secondType->isString()->yes()) { + if ($firstType instanceof ClassStringType && $secondType instanceof StringType) { return \false; } - if (!$firstType->isString()->yes()) { + if (!$firstType instanceof StringType) { return \get_class($firstType) !== \get_class($secondType); } if (!$secondType instanceof ClassStringType) { @@ -54,15 +58,15 @@ final class ScalarTypeComparator } private function isScalarType(Type $type) : bool { - if ($type->isString()->yes()) { + if ($type instanceof StringType) { return \true; } - if ($type->isFloat()->yes()) { + if ($type instanceof FloatType) { return \true; } - if ($type->isInteger()->yes()) { + if ($type instanceof IntegerType) { return \true; } - return $type->isBoolean()->yes(); + return $type instanceof BooleanType; } } diff --git a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/BoolUnionTypeAnalyzer.php b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/BoolUnionTypeAnalyzer.php index 8fd0b4680e4..a76665b1ba7 100644 --- a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/BoolUnionTypeAnalyzer.php +++ b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/BoolUnionTypeAnalyzer.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer; +use PHPStan\Type\BooleanType; use PHPStan\Type\NullType; use PHPStan\Type\UnionType; final class BoolUnionTypeAnalyzer @@ -10,7 +11,7 @@ final class BoolUnionTypeAnalyzer public function isBoolUnionType(UnionType $unionType) : bool { foreach ($unionType->getTypes() as $unionedType) { - if (!$unionedType->isBoolean()->yes()) { + if (!$unionedType instanceof BooleanType) { return \false; } } @@ -24,7 +25,7 @@ final class BoolUnionTypeAnalyzer $hasNullable = \true; continue; } - if ($unionedType->isBoolean()->yes()) { + if ($unionedType instanceof BooleanType) { continue; } return \false; diff --git a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php index 55fb9f4a15f..3878a91a071 100644 --- a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php +++ b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php @@ -4,11 +4,15 @@ declare (strict_types=1); namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer; use PHPStan\Type\ArrayType; +use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; use PHPStan\Type\IterableType; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectWithoutClassType; +use PHPStan\Type\StringType; use PHPStan\Type\TypeWithClassName; use PHPStan\Type\UnionType; use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis; @@ -86,16 +90,16 @@ final class UnionTypeAnalyzer return \false; } foreach ($types as $type) { - if ($type->isString()->yes() && !$type instanceof ConstantStringType) { + if ($type instanceof StringType && !$type instanceof ConstantStringType) { continue; } - if ($type->isFloat()->yes()) { + if ($type instanceof FloatType) { continue; } - if ($type->isInteger()->yes()) { + if ($type instanceof IntegerType) { continue; } - if ($type->isBoolean()->yes()) { + if ($type instanceof BooleanType) { continue; } return \false; diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php index 76e3c2373e2..ac5fe9b7217 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php @@ -14,6 +14,7 @@ use PHPStan\Type\ClassStringType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Generic\GenericClassStringType; +use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\NeverType; use PHPStan\Type\ObjectType; @@ -208,7 +209,7 @@ final class ArrayTypeMapper implements TypeMapperInterface } private function isIntegerKeyAndNonNestedArray(ArrayType $arrayType) : bool { - if (!$arrayType->getKeyType()->isInteger()->yes()) { + if (!$arrayType->getKeyType() instanceof IntegerType) { return \false; } return !$arrayType->getItemType() instanceof ArrayType; diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php index e13ee8f065e..415fa03fa8c 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php @@ -204,7 +204,7 @@ final class UnionTypeMapper implements TypeMapperInterface private function mapNullabledType(Type $nullabledType, string $typeKind) : ?Node { // void cannot be nullable - if ($nullabledType->isVoid()->yes()) { + if ($nullabledType instanceof VoidType) { return null; } $nullabledTypeNode = $this->phpStanStaticTypeMapper->mapToPhpParserNode($nullabledType, $typeKind); diff --git a/packages/PhpAttribute/NodeAnalyzer/ExprParameterReflectionTypeCorrector.php b/packages/PhpAttribute/NodeAnalyzer/ExprParameterReflectionTypeCorrector.php index 57942f48313..394bc370d7b 100644 --- a/packages/PhpAttribute/NodeAnalyzer/ExprParameterReflectionTypeCorrector.php +++ b/packages/PhpAttribute/NodeAnalyzer/ExprParameterReflectionTypeCorrector.php @@ -10,6 +10,8 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ReflectionProvider; +use PHPStan\Type\BooleanType; +use PHPStan\Type\IntegerType; use PHPStan\Type\TypeCombinator; use Rector\Core\PhpParser\Node\NodeFactory; use Rector\StaticTypeMapper\StaticTypeMapper; @@ -87,10 +89,10 @@ final class ExprParameterReflectionTypeCorrector } $clearParameterType = TypeCombinator::removeNull($parameterType); // correct type - if ($clearParameterType->isInteger()->yes() && $item instanceof String_) { + if ($clearParameterType instanceof IntegerType && $item instanceof String_) { return new LNumber((int) $item->value); } - if ($clearParameterType->isBoolean()->yes() && $item instanceof String_) { + if ($clearParameterType instanceof BooleanType && $item instanceof String_) { if (\strtolower($item->value) === 'true') { return $this->nodeFactory->createTrue(); } diff --git a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php index 9c8154bce18..e8312f0633f 100644 --- a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php +++ b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php @@ -13,6 +13,7 @@ use PHPStan\Reflection\FunctionVariantWithPhpDocs; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; +use PHPStan\Type\VoidType; use Rector\Core\FileSystem\FilePathHelper; use Rector\Core\PhpParser\AstResolver; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -185,7 +186,7 @@ final class ClassMethodReturnTypeOverrideGuard return \true; } $childReturnType = $this->returnTypeInferer->inferFunctionLike($method); - if ($returnType->isVoid()->yes() && !$childReturnType->isVoid()->yes()) { + if ($returnType instanceof VoidType && !$childReturnType instanceof VoidType) { return \true; } } diff --git a/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php b/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php index da6f944b4db..1b8976a1632 100644 --- a/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php +++ b/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Cast\Bool_; +use PHPStan\Type\BooleanType; use PHPStan\Type\UnionType; use Rector\Core\PhpParser\Node\NodeFactory; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -71,7 +72,7 @@ final class ExprBoolCaster return \false; } $exprType = $this->nodeTypeResolver->getType($expr); - if ($exprType->isBoolean()->yes()) { + if ($exprType instanceof BooleanType) { return \false; } return !$expr instanceof BinaryOp; diff --git a/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php b/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php index b7d2d1ca063..0a3ef219bd6 100644 --- a/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php +++ b/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; +use PHPStan\Type\BooleanType; use Rector\Core\NodeManipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -84,7 +85,7 @@ CODE_SAMPLE /** @var BooleanAnd|BooleanOr $booleanExpr */ $booleanExpr = $expression->expr; $leftStaticType = $this->getType($booleanExpr->left); - if (!$leftStaticType->isBoolean()->yes()) { + if (!$leftStaticType instanceof BooleanType) { return null; } $exprLeft = $booleanExpr->left instanceof BooleanNot ? $booleanExpr->left->expr : $booleanExpr->left; diff --git a/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php b/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php index f29df3c7844..cd401edcc25 100644 --- a/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php +++ b/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; +use PHPStan\Type\BooleanType; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -66,11 +67,11 @@ CODE_SAMPLE if ($node->expr instanceof Identical) { $identical = $node->expr; $leftType = $this->getType($identical->left); - if (!$leftType->isBoolean()->yes()) { + if (!$leftType instanceof BooleanType) { return null; } $rightType = $this->getType($identical->right); - if (!$rightType->isBoolean()->yes()) { + if (!$rightType instanceof BooleanType) { return null; } return new NotIdentical($identical->left, $identical->right); @@ -80,11 +81,11 @@ CODE_SAMPLE private function processIdentical(Identical $identical) : ?NotIdentical { $leftType = $this->getType($identical->left); - if (!$leftType->isBoolean()->yes()) { + if (!$leftType instanceof BooleanType) { return null; } $rightType = $this->getType($identical->right); - if (!$rightType->isBoolean()->yes()) { + if (!$rightType instanceof BooleanType) { return null; } if ($identical->left instanceof BooleanNot) { diff --git a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php index caf4fa45eba..e11d60659d8 100644 --- a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php +++ b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Variable; +use PHPStan\Type\BooleanType; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -54,11 +55,11 @@ CODE_SAMPLE public function refactor(Node $node) : ?Node { $leftType = $this->getType($node->left); - if ($leftType->isBoolean()->yes() && !$this->valueResolver->isTrueOrFalse($node->left)) { + if ($leftType instanceof BooleanType && !$this->valueResolver->isTrueOrFalse($node->left)) { return $this->processBoolTypeToNotBool($node, $node->left, $node->right); } $rightType = $this->getType($node->right); - if (!$rightType->isBoolean()->yes()) { + if (!$rightType instanceof BooleanType) { return null; } if ($this->valueResolver->isTrueOrFalse($node->right)) { @@ -88,7 +89,7 @@ CODE_SAMPLE } $leftExprType = $this->getType($leftExpr); // keep as it is, readable enough - if ($leftExpr instanceof Variable && $leftExprType->isBoolean()->yes()) { + if ($leftExpr instanceof Variable && $leftExprType instanceof BooleanType) { return null; } return new BooleanNot($leftExpr); diff --git a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php index c530b329cf8..f3d7fa6fcc0 100644 --- a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php @@ -22,6 +22,9 @@ use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\If_; +use PHPStan\Type\BooleanType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use Rector\Core\Rector\AbstractRector; @@ -106,7 +109,7 @@ CODE_SAMPLE return null; } $conditionStaticType = $this->getType($conditionNode); - if ($conditionStaticType->isBoolean()->yes()) { + if ($conditionStaticType instanceof BooleanType) { return null; } $binaryOp = $this->resolveNewConditionNode($conditionNode, $isNegated); @@ -143,10 +146,10 @@ CODE_SAMPLE return $this->resolveString($isNegated, $expr); } $exprType = $this->getType($expr); - if ($exprType->isInteger()->yes()) { + if ($exprType instanceof IntegerType) { return $this->resolveInteger($isNegated, $expr); } - if ($exprType->isFloat()->yes()) { + if ($exprType instanceof FloatType) { return $this->resolveFloat($isNegated, $expr); } if ($this->nodeTypeResolver->isNullableTypeOfSpecificType($expr, ObjectType::class)) { diff --git a/rules/CodeQuality/Rector/Ternary/UnnecessaryTernaryExpressionRector.php b/rules/CodeQuality/Rector/Ternary/UnnecessaryTernaryExpressionRector.php index 64918798bbf..8ccf692f82b 100644 --- a/rules/CodeQuality/Rector/Ternary/UnnecessaryTernaryExpressionRector.php +++ b/rules/CodeQuality/Rector/Ternary/UnnecessaryTernaryExpressionRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Cast\Bool_; use PhpParser\Node\Expr\Ternary; +use PHPStan\Type\BooleanType; use Rector\Core\PhpParser\Node\AssignAndBinaryMap; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -93,7 +94,7 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector private function processTrueIfExpressionWithFalseElseExpression(Expr $expr) : Expr { $exprType = $this->getType($expr); - if ($exprType->isBoolean()->yes()) { + if ($exprType instanceof BooleanType) { return $expr; } return new Bool_($expr); @@ -102,13 +103,13 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector { if ($expr instanceof BooleanNot) { $negatedExprType = $this->getType($expr->expr); - if ($negatedExprType->isBoolean()->yes()) { + if ($negatedExprType instanceof BooleanType) { return $expr->expr; } return new Bool_($expr->expr); } $exprType = $this->getType($expr); - if ($exprType->isBoolean()->yes()) { + if ($exprType instanceof BooleanType) { return new BooleanNot($expr); } return new BooleanNot(new Bool_($expr)); diff --git a/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php b/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php index 22bbd78bfb1..7c1286f7dff 100644 --- a/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php +++ b/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Trait_; +use PHPStan\Type\BooleanType; use Rector\Core\Rector\AbstractRector; use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -85,6 +86,6 @@ CODE_SAMPLE private function isBoolDocType(Property $property) : bool { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); - return $phpDocInfo->getVarType()->isBoolean()->yes(); + return $phpDocInfo->getVarType() instanceof BooleanType; } } diff --git a/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php b/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php index 413c35aadcb..48457e8d36f 100644 --- a/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php +++ b/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Return_; use PhpParser\NodeTraverser; +use PHPStan\Type\BooleanType; use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer; use Rector\Core\NodeManipulator\IfManipulator; use Rector\Core\PhpParser\Comparing\NodeComparator; @@ -134,7 +135,7 @@ CODE_SAMPLE return \false; } $type = $this->nodeTypeResolver->getType($cond); - if (!$type->isBoolean()->yes()) { + if (!$type instanceof BooleanType) { return \false; } $nextNode = $ifWithOnlyReturns[0]->getAttribute(AttributeKey::NEXT_NODE); diff --git a/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php b/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php index 0f77e07ffba..eef0f6f2b28 100644 --- a/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php +++ b/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\Ternary; +use PHPStan\Type\BooleanType; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -69,7 +70,7 @@ CODE_SAMPLE return null; } $ifType = $this->getType($node->if); - if (!$ifType->isBoolean()->yes()) { + if (!$ifType instanceof BooleanType) { return null; } return new BooleanAnd($node->cond, $node->if); diff --git a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php index a6a037da15a..13b18882f32 100644 --- a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php +++ b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php @@ -35,6 +35,7 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Type\MixedType; use PHPStan\Type\Type; +use PHPStan\Type\VoidType; use Rector\Core\PhpParser\AstResolver; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Node\NodeFactory; @@ -359,7 +360,7 @@ final class AnonymousFunctionFactory */ private function resolveStmts(FunctionVariantWithPhpDocs $functionVariantWithPhpDocs, $innerMethodCall) : array { - if ($functionVariantWithPhpDocs->getReturnType()->isVoid()->yes()) { + if ($functionVariantWithPhpDocs->getReturnType() instanceof VoidType) { return [new Expression($innerMethodCall)]; } return [new Return_($innerMethodCall)]; diff --git a/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php b/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php index 559c307b671..832fd7792f4 100644 --- a/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php +++ b/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php @@ -12,6 +12,8 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Variable; use PHPStan\Type\ArrayType; +use PHPStan\Type\IntegerType; +use PHPStan\Type\StringType; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; @@ -134,13 +136,16 @@ CODE_SAMPLE } private function isArrayKeyTypeAllowed(ArrayType $arrayType) : bool { - if ($arrayType->getKeyType()->isInteger()->yes()) { - return \true; + $allowedKeyTypes = [IntegerType::class]; + if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) { + $allowedKeyTypes[] = StringType::class; } - if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) { - return \false; + foreach ($allowedKeyTypes as $allowedKeyType) { + if ($arrayType->getKeyType() instanceof $allowedKeyType) { + return \true; + } } - return $arrayType->getKeyType()->isString()->yes(); + return \false; } private function resolveValue(Expr $expr) : Expr { diff --git a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php index 14968ec4fef..17a2988fd59 100644 --- a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php +++ b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Scalar\LNumber; +use PHPStan\Type\IntegerType; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -52,7 +53,7 @@ final class MbStrrposEncodingArgumentPositionRector extends AbstractRector imple return null; } $secondArgType = $this->getType($node->args[2]->value); - if ($secondArgType->isInteger()->yes()) { + if ($secondArgType instanceof IntegerType) { return null; } $node->args[3] = $node->args[2]; diff --git a/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php b/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php index 2c051047710..c319e8bc1ae 100644 --- a/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php +++ b/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Case_; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; +use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; @@ -45,7 +46,7 @@ final class SwitchAnalyzer } $uniqueTypes = $this->typeFactory->uniquateTypes($types); $countUniqueTypes = \count($uniqueTypes); - if ($countUniqueTypes === 1 && $uniqueTypes[0]->isInteger()->yes()) { + if ($countUniqueTypes === 1 && $uniqueTypes[0] instanceof IntegerType) { $switchCondType = $this->nodeTypeResolver->getType($expr); if (!$switchCondType instanceof MixedType && $switchCondType->isString()->maybe()) { return \true; diff --git a/rules/Strict/NodeFactory/ExactCompareFactory.php b/rules/Strict/NodeFactory/ExactCompareFactory.php index 79f957d984a..341b08404c6 100644 --- a/rules/Strict/NodeFactory/ExactCompareFactory.php +++ b/rules/Strict/NodeFactory/ExactCompareFactory.php @@ -14,6 +14,8 @@ use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; +use PHPStan\Type\BooleanType; +use PHPStan\Type\IntegerType; use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; @@ -39,10 +41,10 @@ final class ExactCompareFactory if ($exprType->isString()->yes()) { return new Identical($expr, new String_('')); } - if ($exprType->isInteger()->yes()) { + if ($exprType instanceof IntegerType) { return new Identical($expr, new LNumber(0)); } - if ($exprType->isBoolean()->yes()) { + if ($exprType instanceof BooleanType) { return new Identical($expr, $this->nodeFactory->createFalse()); } if ($exprType->isArray()->yes()) { @@ -64,7 +66,7 @@ final class ExactCompareFactory if ($exprType->isString()->yes()) { return new NotIdentical($expr, new String_('')); } - if ($exprType->isInteger()->yes()) { + if ($exprType instanceof IntegerType) { return new NotIdentical($expr, new LNumber(0)); } if ($exprType->isArray()->yes()) { @@ -81,7 +83,7 @@ final class ExactCompareFactory private function createFromUnionType(UnionType $unionType, Expr $expr, bool $treatAsNotEmpty) { $unionType = TypeCombinator::removeNull($unionType); - if ($unionType->isBoolean()->yes()) { + if ($unionType instanceof BooleanType) { return new Identical($expr, $this->nodeFactory->createTrue()); } if ($unionType instanceof TypeWithClassName) { @@ -170,7 +172,7 @@ final class ExactCompareFactory $compareExprs = $this->collectCompareExprs($unionType, $expr, $treatAsNonEmpty); return $this->createBooleanOr($compareExprs); } - if ($unionType->isBoolean()->yes()) { + if ($unionType instanceof BooleanType) { return new NotIdentical($expr, $this->nodeFactory->createTrue()); } if ($unionType instanceof TypeWithClassName) { diff --git a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php index f1e3cfce0f7..97f8da74696 100644 --- a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\Rector\ArrowFunction; use PhpParser\Node; use PhpParser\Node\Expr\ArrowFunction; +use PHPStan\Type\VoidType; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; @@ -42,7 +43,7 @@ CODE_SAMPLE return null; } $type = $this->getType($node->expr); - if ($type->isVoid()->yes()) { + if ($type instanceof VoidType) { return null; } $returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN); diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php index 5c3a3c1e3cf..8488493f136 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php @@ -19,6 +19,7 @@ use PhpParser\Node\UnionType as PhpParserUnionType; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\UnionType; +use PHPStan\Type\VoidType; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; @@ -152,7 +153,7 @@ CODE_SAMPLE { $resolvedType = $this->nodeTypeResolver->getType($arrowFunction->expr); // void type is not accepted for arrow functions - https://www.php.net/manual/en/functions.arrow.php#125673 - if ($resolvedType->isVoid()->yes()) { + if ($resolvedType instanceof VoidType) { return null; } $returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($resolvedType, TypeKind::RETURN); @@ -170,7 +171,7 @@ CODE_SAMPLE $inferReturnType = $this->returnTypeInferer->inferFunctionLike($node); if ($inferReturnType instanceof UnionType) { foreach ($inferReturnType->getTypes() as $type) { - if ($type->isVoid()->yes()) { + if ($type instanceof VoidType) { return \true; } } diff --git a/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php index 100ca8bc108..9b405efaa51 100644 --- a/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php +++ b/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php @@ -118,13 +118,13 @@ final class AlwaysStrictScalarExprAnalyzer if ($type->isString()->yes() && !$type instanceof ConstantStringType) { return \true; } - if ($type->isFloat()->yes()) { + if ($type instanceof FloatType) { return \true; } - if ($type->isInteger()->yes()) { + if ($type instanceof IntegerType) { return \true; } - return $type->isBoolean()->yes(); + return $type instanceof BooleanType; } private function resolveTypeFromScalar(Scalar $scalar) : ?\PHPStan\Type\Type { diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php index d4ae0240a09..aabf0417da9 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php @@ -16,11 +16,13 @@ use PhpParser\Node\Stmt\Return_; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\BenevolentUnionType; +use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\ThisType; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; use PHPStan\Type\UnionType; +use PHPStan\Type\VoidType; use Rector\Core\Enum\ObjectReference; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Php\PhpVersionProvider; @@ -144,7 +146,7 @@ final class ReturnTypeInferer */ private function resolveTypeWithVoidHandling($functionLike, Type $resolvedType) : Type { - if ($resolvedType->isVoid()->yes()) { + if ($resolvedType instanceof VoidType) { if ($functionLike instanceof ArrowFunction) { return new MixedType(); } @@ -161,7 +163,7 @@ final class ReturnTypeInferer } if ($resolvedType instanceof UnionType) { $benevolentUnionTypeIntegerType = $this->resolveBenevolentUnionTypeInteger($functionLike, $resolvedType); - if ($benevolentUnionTypeIntegerType->isInteger()->yes()) { + if ($benevolentUnionTypeIntegerType instanceof IntegerType) { return $benevolentUnionTypeIntegerType; } } @@ -169,15 +171,16 @@ final class ReturnTypeInferer } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike + * @return \PHPStan\Type\UnionType|\PHPStan\Type\IntegerType */ - private function resolveBenevolentUnionTypeInteger($functionLike, UnionType $unionType) : Type + private function resolveBenevolentUnionTypeInteger($functionLike, UnionType $unionType) { $types = $unionType->getTypes(); $countTypes = \count($types); if ($countTypes !== 2) { return $unionType; } - if (!($types[0]->isInteger()->yes() && $types[1]->isString()->yes())) { + if (!($types[0] instanceof IntegerType && $types[1]->isString()->yes())) { return $unionType; } if (!$functionLike instanceof ArrowFunction) { diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php index 3e2c2a59b61..e90de646f58 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php @@ -188,7 +188,7 @@ final class ReturnedNodesReturnTypeInfererTypeInferer if ($resolvedType instanceof MixedType || $this->isArrayTypeMixed($resolvedType)) { $correctedType = $this->inferFromReturnedMethodCall($return, $functionLike); // override only if has some extra value - if (!$correctedType instanceof MixedType && !$correctedType->isVoid()->yes()) { + if (!$correctedType instanceof MixedType && !$correctedType instanceof VoidType) { return $correctedType; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 6281f07e2d4..23b0b572514 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'e66317aeb276bb0b544e7b4b55057c9dab5fbb73'; + public const PACKAGE_VERSION = 'dbb0e196a43d8c14a9de6abeef8fe081e95c51c2'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-04-08 12:28:02'; + public const RELEASE_DATE = '2023-04-08 20:19:33'; /** * @var int */ diff --git a/src/PhpParser/Node/AssignAndBinaryMap.php b/src/PhpParser/Node/AssignAndBinaryMap.php index 71a38a4ff60..5d9e03d10b2 100644 --- a/src/PhpParser/Node/AssignAndBinaryMap.php +++ b/src/PhpParser/Node/AssignAndBinaryMap.php @@ -42,6 +42,7 @@ use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Cast\Bool_; use PHPStan\Analyser\Scope; +use PHPStan\Type\BooleanType; use Rector\NodeTypeResolver\Node\AttributeKey; final class AssignAndBinaryMap { @@ -96,7 +97,7 @@ final class AssignAndBinaryMap return new Bool_($expr); } $type = $scope->getType($expr); - if ($type->isBoolean()->yes()) { + if ($type instanceof BooleanType) { return $expr; } return new Bool_($expr); diff --git a/vendor/autoload.php b/vendor/autoload.php index 92c201dfa12..918edbf6680 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173::getLoader(); +return ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index d17d3fc505d..7850e0713b4 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173 +class ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit5655b4feae432f84294783c771fa6ebd::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 201e835f0ce..1cf67f8070d 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit827ced5e8bddbb7f983434d5761e2173 +class ComposerStaticInit5655b4feae432f84294783c771fa6ebd { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3135,9 +3135,9 @@ class ComposerStaticInit827ced5e8bddbb7f983434d5761e2173 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$classMap; }, null, ClassLoader::class); }