Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/PhpParser/Node/Resolver/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\Stmt\Use_;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\SmartFileSystem\SmartFileInfo;

final class NameResolver
{
Expand All @@ -46,19 +44,8 @@ public function isNames(Node $node, array $names): bool
public function isName(Node $node, string $name): bool
{
if ($node instanceof MethodCall) {
$debugBacktrace = debug_backtrace();

$previousCaller = $debugBacktrace[1];
$fileInfo = new SmartFileInfo($previousCaller['file']);
$location = $fileInfo->getRelativeFilePathFromDirectory(getcwd()) . ':' . $previousCaller['line'];

throw new ShouldNotHappenException(sprintf(
'Cannot get name on "%s" node. Use "$node->name" or check if "$node->class" is of "%s" type.%sCalled in: %s',
MethodCall::class,
Name::class,
PHP_EOL,
$location
));
// method call cannot have a name, only the variable or method name
return false;
}

$resolvedName = $this->getName($node);
Expand Down