Skip to content

Commit

Permalink
Merge 3f8efeb into dfb3cc7
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 9, 2020
2 parents dfb3cc7 + 3f8efeb commit af8dc0a
Showing 1 changed file with 2 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class ClassMethodParamVendorLockResolver extends AbstractNodeVendorLockResolver
Expand All @@ -24,10 +23,8 @@ public function isVendorLocked(ClassMethod $classMethod, int $paramPosition): bo
return false;
}

/** @var string $methodName */
$methodName = $this->nodeNameResolver->getName($classMethod);
if (! is_string($methodName)) {
throw new ShouldNotHappenException();
}

// @todo extract to some "inherited parent method" service
/** @var string|null $parentClassName */
Expand All @@ -45,8 +42,7 @@ public function isVendorLocked(ClassMethod $classMethod, int $paramPosition): bo
return false;
}

$interfaceNames = $this->classManipulator->getClassLikeNodeParentInterfaceNames($classNode);
return $this->isInterfaceParamVendorLockin($interfaceNames, $methodName);
return $this->isMethodVendorLockedByInterface($classNode, $methodName);
}

private function isParentClassVendorLocking(int $paramPosition, string $parentClassName, string $methodName): ?bool
Expand Down Expand Up @@ -74,24 +70,4 @@ private function isParentClassVendorLocking(int $paramPosition, string $parentCl

return null;
}

private function isInterfaceParamVendorLockin(array $interfaceNames, string $methodName): bool
{
foreach ($interfaceNames as $interfaceName) {
$interface = $this->parsedNodeCollector->findInterface($interfaceName);
// parent class method in local scope → it's ok
// @todo validate type is conflicting
if ($interface !== null && $interface->getMethod($methodName) !== null) {
return false;
}

if (method_exists($interfaceName, $methodName)) {
// parent class method in external scope → it's not ok
// @todo validate type is conflicting
return true;
}
}

return false;
}
}

0 comments on commit af8dc0a

Please sign in to comment.