Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 19, 2021
1 parent 9b9e7fd commit 5b7de30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,22 @@ public function isVendorLocked(ClassMethod $classMethod, int $paramPosition): bo
return false;
}

if (! $this->classReflectionAncestorAnalyzer->hasAncestors($classReflection)) {
return false;
$methodName = $this->nodeNameResolver->getName($classMethod);
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
// skip self
if ($ancestorClassReflection === $classReflection) {
continue;
}

if (! $classReflection->hasNativeMethod($methodName)) {
continue;
}
}

$methodName = $this->nodeNameResolver->getName($classMethod);
// if (! $this->classReflectionAncestorAnalyzer->hasAncestors($classReflection)) {
// return false;
// }


if ($classReflection->getParentClass() !== false) {
$vendorLock = $this->isParentClassVendorLocking(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,11 @@
namespace Rector\VendorLocker\Reflection;

use PHPStan\Reflection\ClassReflection;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;

final class ClassReflectionAncestorAnalyzer
{
/**
* @var FamilyRelationsAnalyzer
*/
private $familyRelationsAnalyzer;

public function __construct(FamilyRelationsAnalyzer $familyRelationsAnalyzer)
{
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
}

public function hasAncestors(ClassReflection $classReflection): bool
{
if ($classReflection->isClass()) {
// has at least interface
if ($classReflection->getInterfaces() !== []) {
return true;
}

// has at least one parent class
if ($classReflection->getParents() !== []) {
return true;
}

$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
return $childrenClassReflections !== [];
}

if ($classReflection->isInterface()) {
return $classReflection->getInterfaces() !== [];
}

return false;
return $classReflection->getAncestors() !== [$classReflection];
}
}
4 changes: 0 additions & 4 deletions rules/CodeQuality/NodeAnalyzer/ForeachAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ function (Node $node) use ($foreachedValue, $singleValue, $keyValueName): ?Expr
}

// is dim same as key value name, ...[$i]
// if ($node->dim === null) {
// return null;
// }
//
if (! $node->dim instanceof Variable) {
return null;
}
Expand Down

0 comments on commit 5b7de30

Please sign in to comment.