Skip to content

Commit

Permalink
PropertyReflectionFinder - DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 18, 2020
1 parent fd66714 commit aeb9925
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/Rules/Properties/PropertyReflectionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,12 @@ public function findPropertyReflectionsFromNode($propertyFetch, Scope $scope): a
*/
public function findPropertyReflectionFromNode($propertyFetch, Scope $scope): ?FoundPropertyReflection
{
if ($propertyFetch instanceof \PhpParser\Node\Expr\PropertyFetch) {
if (!$propertyFetch->name instanceof \PhpParser\Node\Identifier) {
return null;
}
$propertyHolderType = $scope->getType($propertyFetch->var);
$fetchedOnThis = $propertyHolderType instanceof ThisType && $scope->isInClass();
return $this->findPropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope, $fetchedOnThis);
}

if (!$propertyFetch->name instanceof \PhpParser\Node\Identifier) {
$reflections = $this->findPropertyReflectionsFromNode($propertyFetch, $scope);
if (count($reflections) !== 1) {
return null;
}

if ($propertyFetch->class instanceof \PhpParser\Node\Name) {
$propertyHolderType = new ObjectType($scope->resolveName($propertyFetch->class));
} else {
$propertyHolderType = $scope->getType($propertyFetch->class);
}

$fetchedOnThis = $propertyHolderType instanceof ThisType && $scope->isInClass();

return $this->findPropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope, $fetchedOnThis);
return $reflections[0];
}

private function findPropertyReflection(Type $propertyHolderType, string $propertyName, Scope $scope, bool $fetchedOnThis): ?FoundPropertyReflection
Expand Down

0 comments on commit aeb9925

Please sign in to comment.