Skip to content

Commit

Permalink
[Php56] Skip variable variable on AddDefaultValueForUndefinedVariable…
Browse files Browse the repository at this point in the history
…Rector (#4148)

* [Php56] Skip variable variable on AddDefaultValueForUndefinedVariableRector

* Fixed 🎉

* comment
  • Loading branch information
samsonasik committed Jun 10, 2023
1 parent 6758a5e commit b92e378
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector\Fixture;

class SkipVariableVariable
{
public function run($abcdef = 'foo')
{
$$abcdef = 'test';

return $foo;
}
}
10 changes: 5 additions & 5 deletions rules/Php56/NodeAnalyzer/UndefinedVariableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function resolve(ClassMethod | Function_ | Closure $node): array
return null;
}

// after variable variable, the variable name got unpredictable, just stop
if ($node->name instanceof Variable) {
return NodeTraverser::STOP_TRAVERSAL;
}

if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) {
return null;
}
Expand Down Expand Up @@ -215,11 +220,6 @@ private function shouldSkipVariable(Variable $variable, string $variableName, ar
return true;
}

$checkedVariables = array_filter(
$checkedVariables,
static fn (string $variableName): bool => $variableName !== ''
);

return in_array($variableName, $checkedVariables, true);
}

Expand Down

0 comments on commit b92e378

Please sign in to comment.