From f889e416d94cbfcf3734bb2fd4daf678aa11f8a9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 3 Apr 2024 14:03:17 +0700 Subject: [PATCH] [DeadCode] Remove union with interface on RemoveUselessParamTagRector to make it consistent (#5794) * [DeadCode] Remove union with interface on RemoveUselessParamTagRector * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action --- ...ip_union_of_interface_with_comment.php.inc | 22 --------- ...ace.php.inc => union_of_interface.php.inc} | 24 +++++++++- .../union_of_interface_with_comment.php.inc | 47 +++++++++++++++++++ .../TypeComparator/TypeComparator.php | 6 --- 4 files changed, 70 insertions(+), 29 deletions(-) delete mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface_with_comment.php.inc rename rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/{skip_union_of_interface.php.inc => union_of_interface.php.inc} (50%) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface_with_comment.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface_with_comment.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface_with_comment.php.inc deleted file mode 100644 index 68a2dc15fdc..00000000000 --- a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface_with_comment.php.inc +++ /dev/null @@ -1,22 +0,0 @@ -run(); - } - } -} diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface.php.inc similarity index 50% rename from rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface.php.inc rename to rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface.php.inc index 8329dbe9313..fd87cf33384 100644 --- a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/skip_union_of_interface.php.inc +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface.php.inc @@ -7,7 +7,7 @@ namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\F use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeInterface; use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Source\SomeClass; -class SkipUnionOfInterface { +class UnionOfInterface { /** * @param SomeClass|SomeInterface $someInterface */ @@ -18,3 +18,25 @@ class SkipUnionOfInterface { } } } + +?> +----- +run(); + } + } +} + +?> \ No newline at end of file diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface_with_comment.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface_with_comment.php.inc new file mode 100644 index 00000000000..521f4dc1247 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector/Fixture/union_of_interface_with_comment.php.inc @@ -0,0 +1,47 @@ +run(); + } + } +} + +?> +----- +run(); + } + } +} + +?> diff --git a/src/NodeTypeResolver/TypeComparator/TypeComparator.php b/src/NodeTypeResolver/TypeComparator/TypeComparator.php index 413a7ddc3ce..f752070a82c 100644 --- a/src/NodeTypeResolver/TypeComparator/TypeComparator.php +++ b/src/NodeTypeResolver/TypeComparator/TypeComparator.php @@ -4,9 +4,7 @@ namespace Rector\NodeTypeResolver\TypeComparator; -use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; use PhpParser\Node; -use PhpParser\Node\Name\FullyQualified; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Reflection\ClassReflection; @@ -83,10 +81,6 @@ public function arePhpParserAndPhpStanPhpDocTypesEqual( TypeNode $phpStanDocTypeNode, Node $node ): bool { - if ($phpStanDocTypeNode instanceof UnionTypeNode && $phpParserNode instanceof FullyQualified) { - return false; - } - $phpParserNodeType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($phpParserNode); $phpStanDocType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType( $phpStanDocTypeNode,