From 26213d5465f06d41294f3fe60d1adab88dfdd636 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 13 Oct 2019 01:24:47 +0200 Subject: [PATCH] make ReturnTypeDeclarationRector keep implementation --- .../Rector/FunctionLike/ReturnTypeDeclarationRector.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php index f1a61573053..1ad7b5f0988 100644 --- a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php +++ b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php @@ -134,6 +134,15 @@ PHP if ($node->returnType !== null) { $isSubtype = $this->isSubtypeOf($inferredReturnNode, $node->returnType); + $currentType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node->returnType); + + // is current class implementation/subtype + if ($currentType instanceof ObjectType && $inferedType instanceof ObjectType) { + if (is_a($currentType->getClassName(), $inferedType->getClassName(), true)) { + return null; + } + } + // @see https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters if ($this->isAtLeastPhpVersion('7.4') && $isSubtype) { $node->returnType = $inferredReturnNode;