rector/rules/Defluent/NodeFactory/VariableFromNewFactory.php
Tomas Votruba cdc3b7adef Updated Rector to commit f451b0b8e1e6761ec7f50809745d44d01caba66d
f451b0b8e1 [PHP 8.0] Bump to promoted properties (#4)
2021-05-10 23:39:21 +00:00

29 lines
869 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Defluent\NodeFactory;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Naming\Naming\VariableNaming;
final class VariableFromNewFactory
{
/**
* @var \Rector\Naming\Naming\VariableNaming
*/
private $variableNaming;
public function __construct(\Rector\Naming\Naming\VariableNaming $variableNaming)
{
$this->variableNaming = $variableNaming;
}
public function create(\PhpParser\Node\Expr\New_ $new) : \PhpParser\Node\Expr\Variable
{
$variableName = $this->variableNaming->resolveFromNode($new);
if ($variableName === null) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
return new \PhpParser\Node\Expr\Variable($variableName);
}
}