[TypeDeclaration] Fix interface contract override by docs (#5965)

This commit is contained in:
Tomas Votruba 2021-03-24 00:31:21 +01:00 committed by GitHub
parent 649cb249a1
commit 627d3f721f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 34 deletions

View File

@ -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;

View File

@ -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

View File

@ -41,6 +41,9 @@ final class LocalChildClass extends AbstractLocalParentClass
{
}
/**
* @param int $number
*/
public function changeToo(int $number)
{
}

View File

@ -74,7 +74,7 @@ final class ClassMethodParamTypeCompleter
return true;
}
if ($this->classMethodParamVendorLockResolver->isVendorLocked($classMethod, $position)) {
if ($this->classMethodParamVendorLockResolver->isVendorLocked($classMethod)) {
return true;
}

View File

@ -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;
}