mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-19 07:40:49 +01:00
34 lines
746 B
PHP
34 lines
746 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\NetteKdyby\Naming\VariableNaming;
|
||
|
|
||
|
final class VariableFromNewFactory
|
||
|
{
|
||
|
/**
|
||
|
* @var VariableNaming
|
||
|
*/
|
||
|
private $variableNaming;
|
||
|
|
||
|
public function __construct(VariableNaming $variableNaming)
|
||
|
{
|
||
|
$this->variableNaming = $variableNaming;
|
||
|
}
|
||
|
|
||
|
public function create(New_ $new): Variable
|
||
|
{
|
||
|
$variableName = $this->variableNaming->resolveFromNode($new);
|
||
|
if ($variableName === null) {
|
||
|
throw new ShouldNotHappenException();
|
||
|
}
|
||
|
|
||
|
return new Variable($variableName);
|
||
|
}
|
||
|
}
|