mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 05:03:31 +00:00
68dde1af51
[TypeDeclaration] Skip controller render method on @var to type declaratoin (#1576)
77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Removing\Rector\FuncCall;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\FuncCall;
|
|
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
|
use Rector\Core\Rector\AbstractRector;
|
|
use Rector\Removing\ValueObject\RemoveFuncCallArg;
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|
use RectorPrefix20211227\Webmozart\Assert\Assert;
|
|
/**
|
|
* @see \Rector\Tests\Removing\Rector\FuncCall\RemoveFuncCallArgRector\RemoveFuncCallArgRectorTest
|
|
*/
|
|
final class RemoveFuncCallArgRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
|
{
|
|
/**
|
|
* @deprecated
|
|
* @var string
|
|
*/
|
|
public const REMOVED_FUNCTION_ARGUMENTS = 'removed_function_arguments';
|
|
/**
|
|
* @var RemoveFuncCallArg[]
|
|
*/
|
|
private $removedFunctionArguments = [];
|
|
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
|
{
|
|
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove argument by position by function name', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
|
remove_last_arg(1, 2);
|
|
CODE_SAMPLE
|
|
, <<<'CODE_SAMPLE'
|
|
remove_last_arg(1);
|
|
CODE_SAMPLE
|
|
, [new \Rector\Removing\ValueObject\RemoveFuncCallArg('remove_last_arg', 1)])]);
|
|
}
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeTypes() : array
|
|
{
|
|
return [\PhpParser\Node\Expr\FuncCall::class];
|
|
}
|
|
/**
|
|
* @param FuncCall $node
|
|
*/
|
|
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
|
{
|
|
if ($node->name instanceof \PhpParser\Node\Expr) {
|
|
return null;
|
|
}
|
|
foreach ($this->removedFunctionArguments as $removedFunctionArgument) {
|
|
if (!$this->isName($node->name, $removedFunctionArgument->getFunction())) {
|
|
continue;
|
|
}
|
|
foreach (\array_keys($node->args) as $position) {
|
|
if ($removedFunctionArgument->getArgumentPosition() !== $position) {
|
|
continue;
|
|
}
|
|
$this->nodeRemover->removeArg($node, $position);
|
|
}
|
|
}
|
|
return $node;
|
|
}
|
|
/**
|
|
* @param mixed[] $configuration
|
|
*/
|
|
public function configure(array $configuration) : void
|
|
{
|
|
$removedFunctionArguments = $configuration[self::REMOVED_FUNCTION_ARGUMENTS] ?? $configuration;
|
|
\RectorPrefix20211227\Webmozart\Assert\Assert::allIsAOf($removedFunctionArguments, \Rector\Removing\ValueObject\RemoveFuncCallArg::class);
|
|
$this->removedFunctionArguments = $removedFunctionArguments;
|
|
}
|
|
}
|