2021-01-20 17:17:59 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-01-20 17:17:59 +01:00
|
|
|
namespace Rector\Defluent\NodeFactory;
|
|
|
|
|
|
|
|
use PhpParser\Node\Arg;
|
|
|
|
use PhpParser\Node\Expr\MethodCall;
|
|
|
|
use PhpParser\Node\Expr\Variable;
|
|
|
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
|
|
|
final class FluentMethodCallAsArgFactory
|
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createFluentAsArg(\PhpParser\Node\Expr\MethodCall $methodCall, \PhpParser\Node\Expr\Variable $variable) : \PhpParser\Node\Expr\MethodCall
|
2021-01-20 17:17:59 +01:00
|
|
|
{
|
|
|
|
/** @var Arg $parent */
|
2021-05-10 22:23:08 +00:00
|
|
|
$parent = $methodCall->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
|
2021-01-20 17:17:59 +01:00
|
|
|
/** @var MethodCall $parentParent */
|
2021-05-10 22:23:08 +00:00
|
|
|
$parentParent = $parent->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
|
|
|
|
$lastMethodCall = new \PhpParser\Node\Expr\MethodCall($parentParent->var, $parentParent->name);
|
|
|
|
$lastMethodCall->args[] = new \PhpParser\Node\Arg($variable);
|
2021-01-20 17:17:59 +01:00
|
|
|
return $lastMethodCall;
|
|
|
|
}
|
|
|
|
}
|