diff --git a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php index cb4d3b763dfc..0da457ee7eb0 100644 --- a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php +++ b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php @@ -152,8 +152,7 @@ public function refactor(Node $node): ?Node } } - // @see https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters - if ($this->isAtLeastPhpVersion('7.4') && $isSubtype) { + if ($this->isAtLeastPhpVersion(PhpVersionFeature::COVARIANT_RETURN) && $isSubtype) { $node->returnType = $inferredReturnNode; } elseif (! $isSubtype) { // type override $node->returnType = $inferredReturnNode; diff --git a/src/ValueObject/PhpVersionFeature.php b/src/ValueObject/PhpVersionFeature.php index 2d00ce90d7e4..86b7f731881c 100644 --- a/src/ValueObject/PhpVersionFeature.php +++ b/src/ValueObject/PhpVersionFeature.php @@ -66,6 +66,12 @@ final class PhpVersionFeature */ public const BEFORE_UNION_TYPES = '7.4'; + /** + * @see https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters + * @var string + */ + public const COVARIANT_RETURN = '7.4'; + /** * @var string */