mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-23 11:14:38 +01:00
a8922f7431
skip temporarily match + throws downagrade in symfony/console, very unlikely to run
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Arguments\NodeAnalyzer;
|
|
|
|
use PhpParser\Node\Expr\MethodCall;
|
|
use PhpParser\Node\Expr\StaticCall;
|
|
use PhpParser\Node\Name;
|
|
use Rector\Arguments\ValueObject\ArgumentAdder;
|
|
use Rector\Core\Enum\ObjectReference;
|
|
use Rector\NodeNameResolver\NodeNameResolver;
|
|
final class ArgumentAddingScope
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeNameResolver\NodeNameResolver
|
|
*/
|
|
private $nodeNameResolver;
|
|
/**
|
|
* @api
|
|
* @var string
|
|
*/
|
|
public const SCOPE_PARENT_CALL = 'parent_call';
|
|
/**
|
|
* @api
|
|
* @var string
|
|
*/
|
|
public const SCOPE_METHOD_CALL = 'method_call';
|
|
/**
|
|
* @api
|
|
* @var string
|
|
*/
|
|
public const SCOPE_CLASS_METHOD = 'class_method';
|
|
public function __construct(NodeNameResolver $nodeNameResolver)
|
|
{
|
|
$this->nodeNameResolver = $nodeNameResolver;
|
|
}
|
|
/**
|
|
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $expr
|
|
*/
|
|
public function isInCorrectScope($expr, ArgumentAdder $argumentAdder) : bool
|
|
{
|
|
if ($argumentAdder->getScope() === null) {
|
|
return \true;
|
|
}
|
|
$scope = $argumentAdder->getScope();
|
|
if ($expr instanceof StaticCall) {
|
|
if (!$expr->class instanceof Name) {
|
|
return \false;
|
|
}
|
|
if ($this->nodeNameResolver->isName($expr->class, ObjectReference::PARENT)) {
|
|
return $scope === self::SCOPE_PARENT_CALL;
|
|
}
|
|
return $scope === self::SCOPE_METHOD_CALL;
|
|
}
|
|
// MethodCall
|
|
return $scope === self::SCOPE_METHOD_CALL;
|
|
}
|
|
}
|