mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-13 12:33:52 +01:00
make ReturnTypeDeclarationRector keep implementation (#2151)
make ReturnTypeDeclarationRector keep implementation
This commit is contained in:
commit
ee93b7af8b
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user