diff --git a/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php b/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php index e3a021c2da5..9734d2120ca 100644 --- a/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php +++ b/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php @@ -5,14 +5,12 @@ namespace Rector\CodeQuality\Rector\Equal; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Equal; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotEqual; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; -use Rector\Core\NodeAnalyzer\ExprAnalyzer; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php b/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php index 11cd80ad31f..53c36e1224a 100644 --- a/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php +++ b/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php @@ -14,7 +14,6 @@ use PhpParser\Node\Expr\Cast\Object_; use PhpParser\Node\Expr\Cast\String_; use PhpParser\Node\Expr\MethodCall; -use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Stmt\ClassMethod; diff --git a/rules/Naming/Matcher/ForeachMatcher.php b/rules/Naming/Matcher/ForeachMatcher.php index c4cd002729a..3fdb33bbd89 100644 --- a/rules/Naming/Matcher/ForeachMatcher.php +++ b/rules/Naming/Matcher/ForeachMatcher.php @@ -4,6 +4,7 @@ namespace Rector\Naming\Matcher; +use PhpParser\Node; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\ClassMethod; @@ -23,7 +24,7 @@ public function __construct( public function match(Foreach_ $foreach, ClassMethod|Closure|Function_ $functionLike): ?VariableAndCallForeach { $call = $this->callMatcher->matchCall($foreach); - if ($call === null) { + if (!$call instanceof Node) { return null; } diff --git a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php index 925f8900939..d116c5ec237 100644 --- a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php +++ b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php @@ -26,7 +26,7 @@ public function __construct( public function match(Assign $assign, ClassMethod|Closure|Function_ $functionLike): ?VariableAndCallAssign { $call = $this->callMatcher->matchCall($assign); - if ($call === null) { + if (!$call instanceof Node) { return null; } diff --git a/rules/Privatization/Guard/ParentPropertyLookupGuard.php b/rules/Privatization/Guard/ParentPropertyLookupGuard.php index 53b71fb3519..9aeda9915af 100644 --- a/rules/Privatization/Guard/ParentPropertyLookupGuard.php +++ b/rules/Privatization/Guard/ParentPropertyLookupGuard.php @@ -6,7 +6,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\PropertyFetch; -use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; diff --git a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php index 0f717faf7a7..e885e270c82 100644 --- a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php @@ -56,7 +56,7 @@ public function refactor(Node $node): ?Node } $returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN); - if ($returnTypeNode === null) { + if (!$returnTypeNode instanceof Node) { return null; } diff --git a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php index 7160ed5463e..1ad48fc5aa7 100644 --- a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php @@ -90,7 +90,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node $addPropertyTypeDeclaration->getType(), TypeKind::PROPERTY ); - if ($typeNode === null) { + if (!$typeNode instanceof Node) { // invalid configuration throw new ShouldNotHappenException(); } diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index f13ff752714..a1260455fc2 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -147,7 +147,7 @@ public function refactor(Node $node): ?Node $inferredType = $this->decorateTypeWithNullableIfDefaultPropertyNull($property, $inferredType); $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($inferredType, TypeKind::PROPERTY); - if ($typeNode === null) { + if (!$typeNode instanceof Node) { continue; } diff --git a/src/NodeDecorator/PropertyTypeDecorator.php b/src/NodeDecorator/PropertyTypeDecorator.php index 4b98ac1f381..612454d5db4 100644 --- a/src/NodeDecorator/PropertyTypeDecorator.php +++ b/src/NodeDecorator/PropertyTypeDecorator.php @@ -4,6 +4,7 @@ namespace Rector\Core\NodeDecorator; +use PhpParser\Node; use PhpParser\Node\Stmt\Property; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Type; @@ -35,7 +36,7 @@ public function decorate(Property $property, ?Type $type): void if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::TYPED_PROPERTIES)) { $phpParserType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PROPERTY); - if ($phpParserType !== null) { + if ($phpParserType instanceof Node) { $property->type = $phpParserType; if ($type instanceof GenericObjectType) { diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 612e74a2f57..0f7543e902e 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -153,7 +153,7 @@ public function createParamFromNameAndType(string $name, ?Type $type): Param if ($type instanceof Type) { $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PARAM); - if ($typeNode !== null) { + if ($typeNode instanceof Node) { $param->setType($typeNode); } } @@ -299,7 +299,7 @@ public function createPromotedPropertyParam(PropertyMetadata $propertyMetadata): if ($propertyType instanceof Type) { $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($propertyType, TypeKind::PROPERTY); - if ($typeNode !== null) { + if ($typeNode instanceof Node) { $paramBuilder->setType($typeNode); } }