make ReturnTypeDeclarationRector keep implementation (#2151)

make ReturnTypeDeclarationRector keep implementation
This commit is contained in:
Tomáš Votruba 2019-10-13 01:25:03 +02:00 committed by GitHub
commit ee93b7af8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;