Merge pull request #2400 from rectorphp/class-method-name

return false on MethodCall name to prevent expr errors
This commit is contained in:
Tomáš Votruba 2019-12-05 17:35:45 +01:00 committed by GitHub
commit 40b50a6947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,9 +23,7 @@ use PhpParser\Node\Stmt\Interface_;
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
{
@ -46,19 +44,8 @@ final class NameResolver
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);