diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector/Fixture/skip_generic_union_return_self.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector/Fixture/skip_generic_union_return_self.php.inc new file mode 100644 index 00000000000..4fe32cf9b2b --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector/Fixture/skip_generic_union_return_self.php.inc @@ -0,0 +1,17 @@ + + */ + public function get(): self + { + return $this; + } +} diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php index 62b4f8bb763..11cf7645087 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveDuplicatedReturnSelfDocblockRector.php @@ -12,6 +12,7 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\Generic\GenericObjectType; +use PHPStan\Type\Generic\GenericStaticType; use PHPStan\Type\ObjectType; use PHPStan\Type\StaticType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; @@ -128,7 +129,7 @@ private function isCurrentObjectReturnDocType( $docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, $classMethod); // generic narrowing, e.g. @return self is not a plain duplicate of the native self type - if ($docType instanceof GenericObjectType) { + if ($docType instanceof GenericObjectType || $docType instanceof GenericStaticType) { return false; }