rector/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php

61 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2019-10-13 05:59:52 +00:00
<?php
declare (strict_types=1);
namespace Rector\Transform\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name\FullyQualified;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Rector\Transform\ValueObject\StaticCallToFuncCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202405\Webmozart\Assert\Assert;
2019-09-03 09:11:45 +00:00
/**
* @see \Rector\Tests\Transform\Rector\StaticCall\StaticCallToFuncCallRector\StaticCallToFuncCallRectorTest
2019-09-03 09:11:45 +00:00
*/
final class StaticCallToFuncCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var StaticCallToFuncCall[]
*/
private $staticCallsToFunctions = [];
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Turns static call to function call.', [new ConfiguredCodeSample('OldClass::oldMethod("args");', 'new_function("args");', [new StaticCallToFuncCall('OldClass', 'oldMethod', 'new_function')])]);
}
2018-08-14 22:12:41 +00:00
/**
* @return array<class-string<Node>>
2018-08-14 22:12:41 +00:00
*/
public function getNodeTypes() : array
{
return [StaticCall::class];
}
/**
* @param StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
[Naming] Register RenameForeachValueVariableToMatchExprVariableRector to naming config set (#5696) * [Naming] Register RenameForeachValueVariableToMatchExprVariableRector to naming config set * fix property fetch not from this * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * fix * [ci-review] Rector Rectify * [ci-review] Rector Rectify * fixture fix * phpstan * [ci-review] Rector Rectify * phpstan * extract to separate method for collect assigns by name * adding InflectorSingularResolver service * skip single prefix and length >= 40 * add failing fixture to skip plural camel case * use regex to get camel cases * implemented singularize camel cased * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * phpstan * handle singular verb news -> new * [ci-review] Rector Rectify * fixture fix * handle has * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * phpstan * phpstan * handle left side By * [ci-review] Rector Rectify * re-use resolve call * [ci-review] Rector Rectify * phpstan * [ci-review] Rector Rectify * final touch * final touch * [ci-review] Rector Rectify * [ci-review] Rector Rectify * use previous By in the middle * update $childClassReflection->hasProperty($propertyName) * [ci-review] Rector Rectify * catchKeys * regex fix * fixture * [ci-review] Rector Rectify * try use check array * Revert "try use check array" This reverts commit adb9f767f20ea2544e5ccfc9cfe361ecc929912a. * use files Co-authored-by: kaizen-ci <info@kaizen-ci.org>
2021-03-05 10:55:40 +00:00
foreach ($this->staticCallsToFunctions as $staticCallToFunction) {
if (!$this->isName($node->name, $staticCallToFunction->getMethod())) {
continue;
}
if (!$this->isObjectType($node->class, $staticCallToFunction->getObjectType())) {
continue;
}
return new FuncCall(new FullyQualified($staticCallToFunction->getFunction()), $node->args);
}
return null;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
2020-07-29 23:39:41 +00:00
{
Assert::allIsAOf($configuration, StaticCallToFuncCall::class);
$this->staticCallsToFunctions = $configuration;
2020-07-29 23:39:41 +00:00
}
}