diff --git a/phpstan.neon b/phpstan.neon index 68d8672db93..24dcd8e469d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -475,3 +475,5 @@ parameters: - message: '#Unable to resolve the template type T in call to static method Webmozart\\Assert\\Assert\:\:isInstanceOfAny\(\)#' path: rules/DeadCode/Rector/FunctionLike/NarrowWideUnionReturnTypeRector.php + + - '#Provide more specific return type "Iterator|PhpParser\\Node" over abstract one#' \ No newline at end of file diff --git a/rules/CodeQuality/Rector/Assign/CombinedAssignRector.php b/rules/CodeQuality/Rector/Assign/CombinedAssignRector.php index bf82d870029..6288a466267 100644 --- a/rules/CodeQuality/Rector/Assign/CombinedAssignRector.php +++ b/rules/CodeQuality/Rector/Assign/CombinedAssignRector.php @@ -49,7 +49,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var BinaryOp $binaryNode */ $binaryNode = $node->expr; if (! $this->nodeComparator->areNodesEqual($node->var, $binaryNode->left)) { diff --git a/rules/CodeQuality/Rector/FuncCall/SimplifyFuncGetArgsCountRector.php b/rules/CodeQuality/Rector/FuncCall/SimplifyFuncGetArgsCountRector.php index 20f39ca84ef..b1dc06a072b 100644 --- a/rules/CodeQuality/Rector/FuncCall/SimplifyFuncGetArgsCountRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SimplifyFuncGetArgsCountRector.php @@ -50,7 +50,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var FuncCall $innerFuncCall */ $innerFuncCall = $firstArg->value; if (! $this->isName($innerFuncCall, 'func_get_args')) { diff --git a/rules/CodeQuality/Rector/FuncCall/SimplifyInArrayValuesRector.php b/rules/CodeQuality/Rector/FuncCall/SimplifyInArrayValuesRector.php index a66224a893a..70abeba0ec1 100644 --- a/rules/CodeQuality/Rector/FuncCall/SimplifyInArrayValuesRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SimplifyInArrayValuesRector.php @@ -57,7 +57,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var FuncCall $innerFunCall */ $innerFunCall = $node->args[1]->value; if (! $this->isName($innerFunCall, 'array_values')) { return null; diff --git a/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php b/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php index 62bb4f07eac..aa49de95840 100644 --- a/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php @@ -62,7 +62,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var FuncCall $innerFuncCall */ $innerFuncCall = $firstArg->value; if (! $this->isName($innerFuncCall, 'strtolower')) { return null; diff --git a/rules/CodeQuality/Rector/FuncCall/SingleInArrayToCompareRector.php b/rules/CodeQuality/Rector/FuncCall/SingleInArrayToCompareRector.php index cff2f92b3e3..373b43c242f 100644 --- a/rules/CodeQuality/Rector/FuncCall/SingleInArrayToCompareRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SingleInArrayToCompareRector.php @@ -113,7 +113,6 @@ private function resolveArrayItem(FuncCall $funcCall): ?ArrayItem return null; } - /** @var Array_ $arrayNode */ $arrayNode = $funcCall->args[1]->value; if (count($arrayNode->items) !== 1) { return null; diff --git a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php index 50c628b14b0..3cbeaeb7c05 100644 --- a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php @@ -235,8 +235,6 @@ private function resolveIdentical(Expr $expr, bool $isNegated, String_ $string): { /** * // compare === '' - * - * @var Identical|NotIdentical */ $identical = $isNegated ? new Identical($expr, $string) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveUselessAssignFromPropertyPromotionRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveUselessAssignFromPropertyPromotionRector.php index e6324ee5a00..35f345b4418 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveUselessAssignFromPropertyPromotionRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveUselessAssignFromPropertyPromotionRector.php @@ -97,7 +97,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var Assign $assign */ $assign = $stmt->expr; // has non property fetches assignments, skip diff --git a/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php b/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php index 3eda0672ab3..8b499eca188 100644 --- a/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php +++ b/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php @@ -6,8 +6,6 @@ use PhpParser\Comment\Doc; use PhpParser\Node; -use PhpParser\Node\Expr\PropertyFetch; -use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Nop; use PhpParser\NodeVisitor; @@ -93,7 +91,6 @@ private function hasGetMagic(Expression $expression): bool return false; } - /** @var PropertyFetch|StaticPropertyFetch $propertyFetch */ $propertyFetch = $expression->expr; $phpPropertyReflection = $this->reflectionResolver->resolvePropertyReflectionFromPropertyFetch($propertyFetch); diff --git a/rules/DeadCode/UselessIfCondBeforeForeachDetector.php b/rules/DeadCode/UselessIfCondBeforeForeachDetector.php index fba53d67cec..71402a15f4e 100644 --- a/rules/DeadCode/UselessIfCondBeforeForeachDetector.php +++ b/rules/DeadCode/UselessIfCondBeforeForeachDetector.php @@ -32,7 +32,6 @@ public function isMatchingEmptyAndForeachedExpr(If_ $if, Expr $foreachExpr): boo return false; } - /** @var Empty_ $empty */ $empty = $if->cond; if (! $this->nodeComparator->areNodesEqual($empty->expr, $foreachExpr)) { @@ -66,7 +65,6 @@ public function isMatchingNotEmpty(If_ $if, Expr $foreachExpr, Scope $scope): bo return false; } - /** @var Empty_ $empty */ $empty = $cond->expr; return $this->areCondExprAndForeachExprSame($empty, $foreachExpr, $scope); @@ -85,7 +83,6 @@ public function isMatchingNotIdenticalEmptyArray(If_ $if, Expr $foreachExpr): bo return false; } - /** @var NotIdentical|NotEqual $notIdentical */ $notIdentical = $if->cond; return $this->isMatchingNotBinaryOp($notIdentical, $foreachExpr); diff --git a/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php b/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php index 2912a867edc..bad0b22ac7b 100644 --- a/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php @@ -87,7 +87,6 @@ public function refactor(Node $node): ?Node continue; } - /** @var BooleanOr $booleanOr */ $booleanOr = $stmt->expr; $left = $booleanOr->left; diff --git a/rules/Naming/Naming/ExpectedNameResolver.php b/rules/Naming/Naming/ExpectedNameResolver.php index 872896ef3a5..11112c5c54e 100644 --- a/rules/Naming/Naming/ExpectedNameResolver.php +++ b/rules/Naming/Naming/ExpectedNameResolver.php @@ -63,7 +63,6 @@ public function resolveForAssignNonNew(Assign $assign): ?string return null; } - /** @var Variable $variable */ $variable = $assign->var; return $this->nodeNameResolver->getName($variable); @@ -79,7 +78,6 @@ public function resolveForAssignNew(Assign $assign): ?string return null; } - /** @var New_ $new */ $new = $assign->expr; if (! $new->class instanceof Name) { return null; diff --git a/rules/Php70/Rector/FuncCall/EregToPregMatchRector.php b/rules/Php70/Rector/FuncCall/EregToPregMatchRector.php index e66507b4bf3..1313b823d47 100644 --- a/rules/Php70/Rector/FuncCall/EregToPregMatchRector.php +++ b/rules/Php70/Rector/FuncCall/EregToPregMatchRector.php @@ -158,7 +158,6 @@ private function processSplitLimitArgument(FuncCall $funcCall, string $functionN return; } - /** @var Int_ $limitNumberNode */ $limitNumberNode = $funcCall->args[2]->value; if ($limitNumberNode->value !== 0) { return; diff --git a/rules/Php70/Rector/FuncCall/MultiDirnameRector.php b/rules/Php70/Rector/FuncCall/MultiDirnameRector.php index c9e5705e676..9cc84c7376e 100644 --- a/rules/Php70/Rector/FuncCall/MultiDirnameRector.php +++ b/rules/Php70/Rector/FuncCall/MultiDirnameRector.php @@ -101,7 +101,6 @@ private function matchNestedDirnameFuncCall(FuncCall $funcCall): ?FuncCall return null; } - /** @var Int_ $levelNumber */ $levelNumber = $args[1]->value; $this->nestingLevel += $levelNumber->value; diff --git a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php index 1599eaad212..5a12eff76ba 100644 --- a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php +++ b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php @@ -78,7 +78,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var Identical|NotIdentical $ternaryCompareNode */ $ternaryCompareNode = $node->cond; if ($this->isNullMatch($ternaryCompareNode->left, $ternaryCompareNode->right, $checkedNode)) { return new Coalesce($checkedNode, $fallbackNode); diff --git a/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php b/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php index efdda21a873..32329d96894 100644 --- a/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php +++ b/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php @@ -124,7 +124,6 @@ private function processArrayKeyFirstLast(Node $stmtsAware, int $jumpToKey = 0): continue; } - /** @var Expression $stmt */ $stmt = $stmtsAware->stmts[$key]; if ($this->shouldSkip($stmt)) { continue; diff --git a/rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php b/rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php index e0b111ca9b0..b4c1021cdb8 100644 --- a/rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php +++ b/rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php @@ -41,7 +41,6 @@ public function matchArrowFunctionExpr(Closure $closure): ?Expr return null; } - /** @var Return_ $return */ $return = $onlyStmt; if (! $return->expr instanceof Expr) { return null; diff --git a/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php b/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php index 004cfd00368..344f24d4268 100644 --- a/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php +++ b/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php @@ -34,7 +34,6 @@ public function match(Identical|NotIdentical|Equal|NotEqual $binaryOp): ?StrStar $isPositive = $binaryOp instanceof Identical || $binaryOp instanceof Equal; if ($binaryOp->left instanceof FuncCall && $this->nodeNameResolver->isName($binaryOp->left, 'substr')) { - /** @var FuncCall $funcCall */ $funcCall = $binaryOp->left; $haystack = $funcCall->getArgs()[0] @@ -44,7 +43,6 @@ public function match(Identical|NotIdentical|Equal|NotEqual $binaryOp): ?StrStar } if ($binaryOp->right instanceof FuncCall && $this->nodeNameResolver->isName($binaryOp->right, 'substr')) { - /** @var FuncCall $funcCall */ $funcCall = $binaryOp->right; $haystack = $funcCall->getArgs()[0] diff --git a/rules/Php80/NodeResolver/StrFalseComparisonResolver.php b/rules/Php80/NodeResolver/StrFalseComparisonResolver.php index 9bc44372491..4bd30579aed 100644 --- a/rules/Php80/NodeResolver/StrFalseComparisonResolver.php +++ b/rules/Php80/NodeResolver/StrFalseComparisonResolver.php @@ -34,9 +34,7 @@ public function resolve(Identical | NotIdentical | Equal | NotEqual $expr, array return null; } - /** @var FuncCall $funcCall */ - $funcCall = $expr->right; - return $funcCall; + return $expr->right; } if ($this->valueResolver->isFalse($expr->right)) { @@ -48,9 +46,7 @@ public function resolve(Identical | NotIdentical | Equal | NotEqual $expr, array return null; } - /** @var FuncCall $funcCall */ - $funcCall = $expr->left; - return $funcCall; + return $expr->left; } return null; diff --git a/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php b/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php index 72f8c378ad0..2b3350c354c 100644 --- a/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php +++ b/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php @@ -13,7 +13,6 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Reflection\Php\PhpPropertyReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; @@ -88,7 +87,6 @@ private function resolvePropertyFetchProvidingType( $nativeReflectionClass = $classReflection->getNativeReflection(); foreach ($nativeReflectionClass->getProperties() as $reflectionProperty) { - /** @var PhpPropertyReflection $phpPropertyReflection */ $phpPropertyReflection = $classReflection->getNativeProperty($reflectionProperty->getName()); $readableType = $phpPropertyReflection->getReadableType(); diff --git a/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php index 355cbadcbdc..5ccea80d790 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php @@ -32,7 +32,6 @@ public function hasPropertyFetchReturn(ClassMethod $classMethod, string $propert return false; } - /** @var Return_ $return */ $return = $onlyClassMethodStmt; if (! $return->expr instanceof PropertyFetch) { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php index 8185bd43396..3a965bff1ac 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php @@ -203,7 +203,6 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node, continue; } - /** @var ArrayDimFetch $arrayDimFetch */ $arrayDimFetch = $assign->var; if (! $arrayDimFetch->var instanceof Variable) { continue; @@ -213,7 +212,7 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node, continue; } - if ($arrayDimFetch->dim !== null) { + if ($arrayDimFetch->dim instanceof Expr) { continue; } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromSymfonySerializerRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromSymfonySerializerRector.php index ac9505488ad..f9c00821391 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromSymfonySerializerRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromSymfonySerializerRector.php @@ -102,7 +102,6 @@ public function refactor(Node $node): ?Node return null; } - /** @var MethodCall $returnExpr */ $returnExpr = $node->stmts[0]->expr; if (! $this->isName($returnExpr->name, 'deserialize')) { return null; diff --git a/src/NodeManipulator/ClassDependencyManipulator.php b/src/NodeManipulator/ClassDependencyManipulator.php index f210cddd030..61e43fb1730 100644 --- a/src/NodeManipulator/ClassDependencyManipulator.php +++ b/src/NodeManipulator/ClassDependencyManipulator.php @@ -109,7 +109,6 @@ public function addConstructorDependencyWithCustomAssign( ?Type $type, Assign $assign ): void { - /** @var ClassMethod|null $constructClassMethod */ $constructClassMethod = $this->resolveConstruct($class); if ($constructClassMethod instanceof ClassMethod) { @@ -190,7 +189,6 @@ public function addStmtsToConstructorIfNotThereYet(Class_ $class, array $stmts): private function resolveConstruct(Class_ $class): ?ClassMethod { - /** @var ClassMethod|null $constructorMethod */ $constructorMethod = $class->getMethod(MethodName::CONSTRUCT); // exists in current class diff --git a/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php b/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php index e33e30c3a86..a0d7640d64e 100644 --- a/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php +++ b/src/NodeTypeResolver/NodeTypeResolver/NewTypeResolver.php @@ -74,7 +74,6 @@ private function resolveAnonymousClassType(New_ $new): ObjectWithoutClassType $directParentTypes = []; - /** @var Class_ $class */ $class = $new->class; if ($class->extends instanceof Name) { $parentClass = (string) $class->extends; diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index b5e27242e6d..08ac4123966 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -166,7 +166,6 @@ public function processNodes( // the class reflection is resolved AFTER entering to class node // so we need to get it from the first after this one if ($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Enum_) { - /** @var MutatingScope $mutatingScope */ $mutatingScope = $this->resolveClassOrInterfaceScope($node, $mutatingScope); $node->setAttribute(AttributeKey::SCOPE, $mutatingScope); diff --git a/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php index b17ffcf8a86..b917ce438de 100644 --- a/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php @@ -5,10 +5,12 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; use Nette\Utils\Strings; +use Override; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Use_; use PhpParser\Node\UseItem; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; use Rector\NodeTypeResolver\Node\AttributeKey; /** @@ -64,4 +66,20 @@ public function getShortNameLowered(): string { return strtolower($this->getShortName()); } + + #[Override] + public function equals(Type $type): bool + { + $isEqual = parent::equals($type); + + if ($isEqual) { + return true; + } + + if ($type instanceof self || $type::class === ObjectType::class) { + return $type->getClassName() === $this->getClassName(); + } + + return false; + } } diff --git a/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php b/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php index 2002a36ee79..be77cd201cd 100644 --- a/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php @@ -4,8 +4,25 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; +use Override; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; final class NonExistingObjectType extends ObjectType { + #[Override] + public function equals(Type $type): bool + { + $isEqual = parent::equals($type); + + if ($isEqual) { + return true; + } + + if ($type instanceof self || $type::class === ObjectType::class) { + return $type->getClassName() === $this->getClassName(); + } + + return false; + } } diff --git a/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php index f5e7108eb80..396d28626e9 100644 --- a/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php @@ -43,4 +43,20 @@ public function getFullyQualifiedName(): string { return $this->fullyQualifiedName; } + + #[Override] + public function equals(Type $type): bool + { + $isEqual = parent::equals($type); + + if ($isEqual) { + return true; + } + + if ($type instanceof self || $type::class === ObjectType::class) { + return $type->getClassName() === $this->fullyQualifiedName; + } + + return false; + } }