mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
503a6059f8
a8922f7431
skip temporarily match + throws downagrade in symfony/console, very unlikely to run
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Naming\AssignVariableNameResolver;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Expr\PropertyFetch;
|
|
use Rector\Core\Exception\NotImplementedYetException;
|
|
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
|
|
use Rector\NodeNameResolver\NodeNameResolver;
|
|
/**
|
|
* @implements AssignVariableNameResolverInterface<PropertyFetch>
|
|
*/
|
|
final class PropertyFetchAssignVariableNameResolver implements AssignVariableNameResolverInterface
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeNameResolver\NodeNameResolver
|
|
*/
|
|
private $nodeNameResolver;
|
|
public function __construct(NodeNameResolver $nodeNameResolver)
|
|
{
|
|
$this->nodeNameResolver = $nodeNameResolver;
|
|
}
|
|
public function match(Node $node) : bool
|
|
{
|
|
return $node instanceof PropertyFetch;
|
|
}
|
|
/**
|
|
* @param PropertyFetch $node
|
|
*/
|
|
public function resolve(Node $node) : string
|
|
{
|
|
$varName = $this->nodeNameResolver->getName($node->var);
|
|
if (!\is_string($varName)) {
|
|
throw new NotImplementedYetException();
|
|
}
|
|
$propertyName = $this->nodeNameResolver->getName($node->name);
|
|
if (!\is_string($propertyName)) {
|
|
throw new NotImplementedYetException();
|
|
}
|
|
if ($varName === 'this') {
|
|
return $propertyName;
|
|
}
|
|
return $varName . \ucfirst($propertyName);
|
|
}
|
|
}
|