mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
[TypeDeclaration] Fix interface contract override by docs (#5965)
This commit is contained in:
parent
649cb249a1
commit
627d3f721f
@ -4,11 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\VendorLocker\NodeVendorLocker;
|
||||
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\NodeCollector\NodeCollector\NodeRepository;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
@ -19,19 +17,17 @@ final class ClassMethodParamVendorLockResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
/**
|
||||
* @var NodeRepository
|
||||
*/
|
||||
private $nodeRepository;
|
||||
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, NodeRepository $nodeRepository)
|
||||
public function __construct(NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeRepository = $nodeRepository;
|
||||
}
|
||||
|
||||
public function isVendorLocked(ClassMethod $classMethod, int $paramPosition): bool
|
||||
public function isVendorLocked(ClassMethod $classMethod): bool
|
||||
{
|
||||
if ($classMethod->isMagic()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
if (! $scope instanceof Scope) {
|
||||
return false;
|
||||
@ -42,10 +38,6 @@ final class ClassMethodParamVendorLockResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($classMethod->isMagic()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
|
||||
// skip self
|
||||
@ -53,23 +45,10 @@ final class ClassMethodParamVendorLockResolver
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $ancestorClassReflection->hasNativeMethod($methodName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// class is vendor, its locking us
|
||||
$classLike = $this->nodeRepository->findClassLike($ancestorClassReflection->getName());
|
||||
if (! $classLike instanceof ClassLike) {
|
||||
// parent type
|
||||
if ($ancestorClassReflection->hasNativeMethod($methodName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$classMethod = $classLike->getMethod($methodName);
|
||||
if (! $classMethod instanceof ClassMethod) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$paramType = $classMethod->params[$paramPosition]->type;
|
||||
return $paramType !== null;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -46,13 +46,13 @@ final class VendorLockResolver
|
||||
$this->classMethodVendorLockResolver = $classMethodVendorLockResolver;
|
||||
}
|
||||
|
||||
public function isClassMethodParamLockedIn(Node $node, int $paramPosition): bool
|
||||
public function isClassMethodParamLockedIn(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof ClassMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->classMethodParamVendorLockResolver->isVendorLocked($node, $paramPosition);
|
||||
return $this->classMethodParamVendorLockResolver->isVendorLocked($node);
|
||||
}
|
||||
|
||||
public function isReturnChangeVendorLockedIn(ClassMethod $classMethod): bool
|
||||
|
@ -41,6 +41,9 @@ final class LocalChildClass extends AbstractLocalParentClass
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $number
|
||||
*/
|
||||
public function changeToo(int $number)
|
||||
{
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ final class ClassMethodParamTypeCompleter
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->classMethodParamVendorLockResolver->isVendorLocked($classMethod, $position)) {
|
||||
if ($this->classMethodParamVendorLockResolver->isVendorLocked($classMethod)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -207,11 +207,11 @@ CODE_SAMPLE
|
||||
|
||||
private function shouldSkipParam(Param $param, FunctionLike $functionLike, int $position): bool
|
||||
{
|
||||
if ($this->vendorLockResolver->isClassMethodParamLockedIn($functionLike, $position)) {
|
||||
if ($param->variadic) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($param->variadic) {
|
||||
if ($this->vendorLockResolver->isClassMethodParamLockedIn($functionLike)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user