rector/rules/Defluent/NodeResolver/FirstMethodCallVarResolver.php
Tomas Votruba d56e7982d0 Updated Rector to commit dedd4b55fe3e03cae9bd5ac822cfdccd8deb3fb6
dedd4b55fe make node_helper.php safe for similar names
2021-05-09 20:15:43 +00:00

27 lines
901 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Defluent\NodeResolver;
use PhpParser\Node\Expr;
use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface;
use Rector\Defluent\ValueObject\AssignAndRootExpr;
use Rector\Defluent\ValueObject\FirstAssignFluentCall;
final class FirstMethodCallVarResolver
{
/**
* @param FirstAssignFluentCall|AssignAndRootExpr $firstCallFactoryAware
*/
public function resolve(\Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface $firstCallFactoryAware, int $key) : \PhpParser\Node\Expr
{
if (!$firstCallFactoryAware->isFirstCallFactory()) {
return $firstCallFactoryAware->getCallerExpr();
}
// very first call
if ($key !== 0) {
return $firstCallFactoryAware->getCallerExpr();
}
return $firstCallFactoryAware->getFactoryAssignVariable();
}
}