mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 3cfdad6ce695b2ea651c1d602e37f129f18e585e
3cfdad6ce6
[stabilize] Remove last children method checks (#5538)
This commit is contained in:
parent
c49de5a16c
commit
71406bdeee
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '5e7ecb623ad7fe78a660fe3d2275166492ebdb40';
|
||||
public const PACKAGE_VERSION = '3cfdad6ce695b2ea651c1d602e37f129f18e585e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-31 21:59:22';
|
||||
public const RELEASE_DATE = '2024-01-31 23:19:02';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -9,7 +9,6 @@ use PhpParser\Node\Stmt\Interface_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\Util\Reflection\PrivatesAccessor;
|
||||
final class FamilyRelationsAnalyzer
|
||||
{
|
||||
/**
|
||||
@ -17,42 +16,16 @@ final class FamilyRelationsAnalyzer
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Util\Reflection\PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(ReflectionProvider $reflectionProvider, PrivatesAccessor $privatesAccessor, NodeNameResolver $nodeNameResolver)
|
||||
public function __construct(ReflectionProvider $reflectionProvider, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @return ClassReflection[]
|
||||
* @deprecated as not reliable
|
||||
*/
|
||||
public function getChildrenOfClassReflection(ClassReflection $desiredClassReflection) : array
|
||||
{
|
||||
if ($desiredClassReflection->isFinalByKeyword()) {
|
||||
return [];
|
||||
}
|
||||
/** @var ClassReflection[] $classReflections */
|
||||
$classReflections = $this->privatesAccessor->getPrivateProperty($this->reflectionProvider, 'classes');
|
||||
$childrenClassReflections = [];
|
||||
foreach ($classReflections as $classReflection) {
|
||||
if (!$classReflection->isSubclassOf($desiredClassReflection->getName())) {
|
||||
continue;
|
||||
}
|
||||
$childrenClassReflections[] = $classReflection;
|
||||
}
|
||||
return $childrenClassReflections;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @return string[]
|
||||
|
@ -3,40 +3,24 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\VendorLocker\NodeVendorLocker;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
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\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
||||
use Rector\FileSystem\FilePathHelper;
|
||||
use Rector\NodeAnalyzer\MagicClassMethodAnalyzer;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
use Rector\Reflection\ReflectionResolver;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
|
||||
final class ClassMethodReturnTypeOverrideGuard
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer
|
||||
*/
|
||||
private $familyRelationsAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
|
||||
*/
|
||||
private $returnTypeInferer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\VendorLocker\ParentClassMethodTypeOverrideGuard
|
||||
@ -52,11 +36,9 @@ final class ClassMethodReturnTypeOverrideGuard
|
||||
* @var \Rector\NodeAnalyzer\MagicClassMethodAnalyzer
|
||||
*/
|
||||
private $magicClassMethodAnalyzer;
|
||||
public function __construct(FamilyRelationsAnalyzer $familyRelationsAnalyzer, ReflectionResolver $reflectionResolver, ReturnTypeInferer $returnTypeInferer, ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, FilePathHelper $filePathHelper, MagicClassMethodAnalyzer $magicClassMethodAnalyzer)
|
||||
public function __construct(ReflectionResolver $reflectionResolver, ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, FilePathHelper $filePathHelper, MagicClassMethodAnalyzer $magicClassMethodAnalyzer)
|
||||
{
|
||||
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
$this->returnTypeInferer = $returnTypeInferer;
|
||||
$this->parentClassMethodTypeOverrideGuard = $parentClassMethodTypeOverrideGuard;
|
||||
$this->filePathHelper = $filePathHelper;
|
||||
$this->magicClassMethodAnalyzer = $magicClassMethodAnalyzer;
|
||||
@ -79,37 +61,7 @@ final class ClassMethodReturnTypeOverrideGuard
|
||||
if (!$this->isReturnTypeChangeAllowed($classMethod, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
if ($classMethod->isFinal()) {
|
||||
return \false;
|
||||
}
|
||||
$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
|
||||
if ($childrenClassReflections === []) {
|
||||
return \false;
|
||||
}
|
||||
if ($classMethod->returnType instanceof Node) {
|
||||
return \true;
|
||||
}
|
||||
$returnType = $this->returnTypeInferer->inferFunctionLike($classMethod);
|
||||
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;
|
||||
return $classMethod->isFinal();
|
||||
}
|
||||
private function isReturnTypeChangeAllowed(ClassMethod $classMethod, Scope $scope) : bool
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user