Skip to content

Commit

Permalink
Minor ClassMethodAssignManipulator improvements (#3662)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 23, 2023
1 parent 092fb22 commit 8423831
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/NodeManipulator/ClassMethodAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,13 @@ private function collectReferenceVariableNames(ClassMethod $classMethod): array
$variables = $this->betterNodeFinder->findInstanceOf($classMethod, Variable::class);

foreach ($variables as $variable) {
if ($this->nodeNameResolver->isName($variable, 'this')) {
$variableName = $this->nodeNameResolver->getName($variable);
if ($variableName === 'this' || $variableName === null) {
continue;
}

$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Node && $this->isExplicitlyReferenced($parentNode)) {
$variableName = $this->nodeNameResolver->getName($variable);
if ($variableName === null) {
continue;
}

$referencedVariables[] = $variableName;
continue;
}
Expand All @@ -245,11 +241,6 @@ private function collectReferenceVariableNames(ClassMethod $classMethod): array
continue;
}

$variableName = $this->nodeNameResolver->getName($variable);
if ($variableName === null) {
continue;
}

if (! $this->isCallOrConstructorWithReference($parentNode, $variable, $argumentPosition)) {
continue;
}
Expand Down Expand Up @@ -332,19 +323,19 @@ private function isFuncCallWithReferencedArgument(Node $node, Variable $variable
return false;
}

if (! $this->nodeNameResolver->isNames($node, ['array_shift', '*sort'])) {
if (! isset($node->args[0])) {
return false;
}

if (! isset($node->args[0])) {
if (! $node->args[0] instanceof Arg) {
return false;
}

if (! $node->args[0] instanceof Arg) {
if (! $this->nodeNameResolver->isNames($node, ['array_shift', '*sort'])) {
return false;
}

// is 1t argument
// is 1st argument
return $node->args[0]->value !== $variable;
}

Expand Down

0 comments on commit 8423831

Please sign in to comment.