From ba2d636bcd1c9445eb5a1fa2cdd266a21cce487e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 9 Dec 2023 14:31:59 +0000 Subject: [PATCH] Updated Rector to commit bc544cf6f72f9296403ae906a3be83093ba08076 https://github.com/rectorphp/rector-src/commit/bc544cf6f72f9296403ae906a3be83093ba08076 [TypeDeclaration] Skip has child return different type on ReturnNeverTypeRector (#5343) --- .../ClassMethodReturnTypeOverrideGuard.php | 24 ++++++++++++++++++- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php index 4d329222155..a7c98905764 100644 --- a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php +++ b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php @@ -9,7 +9,10 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionVariantWithPhpDocs; use PHPStan\Reflection\MethodReflection; +use PHPStan\Reflection\ParametersAcceptorSelector; +use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Type\MixedType; +use PHPStan\Type\Type; use Rector\Core\FileSystem\FilePathHelper; use Rector\Core\NodeAnalyzer\MagicClassMethodAnalyzer; use Rector\Core\Reflection\ReflectionResolver; @@ -87,7 +90,26 @@ final class ClassMethodReturnTypeOverrideGuard return \true; } $returnType = $this->returnTypeInferer->inferFunctionLike($classMethod); - return !$returnType->isVoid()->yes(); + return $this->hasChildrenDifferentTypeClassMethod($classMethod, $childrenClassReflections, $returnType); + } + /** + * @param ClassReflection[] $childrenClassReflections + */ + private function hasChildrenDifferentTypeClassMethod(ClassMethod $classMethod, array $childrenClassReflections, Type $returnType) : bool + { + $methodName = $classMethod->name->toString(); + foreach ($childrenClassReflections as $childClassReflection) { + $methodReflection = $childClassReflection->getNativeMethod($methodName); + if (!$methodReflection instanceof PhpMethodReflection) { + continue; + } + $parametersAcceptor = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants()); + $childReturnType = $parametersAcceptor->getNativeReturnType(); + if (!$returnType->isSuperTypeOf($childReturnType)->yes()) { + return \true; + } + } + return \false; } private function isReturnTypeChangeAllowed(ClassMethod $classMethod, Scope $scope) : bool { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index c4b65ed993f..e946a284070 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '6a63c6376124c9604097d85aa4cc77c190bdacd2'; + public const PACKAGE_VERSION = 'bc544cf6f72f9296403ae906a3be83093ba08076'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-12-08 16:09:33'; + public const RELEASE_DATE = '2023-12-09 21:29:50'; /** * @var int */