rector/packages/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php
Tomas Votruba 785f5e3b06 Updated Rector to commit 74f6b181e82f191c1e471d446a029a06dff16619
74f6b181e8 [DX] Remove upgrade RectorConfig set, as last 2 version use only PHP (#2852)
2022-08-29 21:45:23 +00:00

39 lines
1.1 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Defluent\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
/**
* Utils for chain of MethodCall Node:
* "$this->methodCall()->chainedMethodCall()"
*/
final class FluentChainMethodCallNodeAnalyzer
{
public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
{
$callerNode = $methodCall->var;
while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
$callerNode = $callerNode->var;
}
if ($callerNode instanceof MethodCall) {
return $callerNode;
}
return null;
}
/**
* @return \PhpParser\Node\Expr|\PhpParser\Node\Name
*/
public function resolveRootExpr(MethodCall $methodCall)
{
$callerNode = $methodCall->var;
while ($callerNode instanceof MethodCall || $callerNode instanceof StaticCall) {
$callerNode = $callerNode instanceof StaticCall ? $callerNode->class : $callerNode->var;
}
return $callerNode;
}
}