mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-30 21:30:23 +00:00
Make StaticCallToFunctionRector configuration consistent with type as key
This commit is contained in:
parent
a2d68ad756
commit
023522acf2
@ -16,8 +16,10 @@ services:
|
||||
'GuzzleHttp\json_decode': ['GuzzleHttp\Utils', 'jsonDecode']
|
||||
'GuzzleHttp\get_path': ['GuzzleHttp\Utils', 'getPath']
|
||||
Rector\Rector\StaticCall\StaticCallToFunctionRector:
|
||||
'GuzzleHttp\Utils::setPath': 'GuzzleHttp\set_path'
|
||||
'GuzzleHttp\Pool::batch': 'GuzzleHttp\Pool\batch'
|
||||
'GuzzleHttp\Utils':
|
||||
setPath: 'GuzzleHttp\set_path'
|
||||
'GuzzleHttp\Pool':
|
||||
batch: 'GuzzleHttp\Pool\batch'
|
||||
|
||||
Rector\Guzzle\Rector\FuncCall\MessageAsArrayRector: ~
|
||||
Rector\Rector\MethodCall\MethodNameReplacerRector:
|
||||
|
@ -13,16 +13,16 @@ use Rector\RectorDefinition\RectorDefinition;
|
||||
final class StaticCallToFunctionRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
* @var string[][]
|
||||
*/
|
||||
private $staticCallToFunction = [];
|
||||
private $staticCallToFunctionByType = [];
|
||||
|
||||
/**
|
||||
* @param string[] $staticCallToFunction
|
||||
* @param string[][] $staticCallToFunctionByType
|
||||
*/
|
||||
public function __construct(array $staticCallToFunction)
|
||||
public function __construct(array $staticCallToFunctionByType)
|
||||
{
|
||||
$this->staticCallToFunction = $staticCallToFunction;
|
||||
$this->staticCallToFunctionByType = $staticCallToFunctionByType;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
@ -33,7 +33,9 @@ final class StaticCallToFunctionRector extends AbstractRector
|
||||
'new_function("args");',
|
||||
[
|
||||
'$staticCallToFunction' => [
|
||||
'OldClass::oldMethod' => 'new_function',
|
||||
'OldClass' => [
|
||||
'oldMethod' => 'new_function',
|
||||
],
|
||||
],
|
||||
]
|
||||
),
|
||||
@ -53,21 +55,20 @@ final class StaticCallToFunctionRector extends AbstractRector
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$staticCalls = array_keys($this->staticCallToFunction);
|
||||
$activeStaticCall = null;
|
||||
foreach ($staticCalls as $staticCall) {
|
||||
[$class, $method] = explode('::', $staticCall);
|
||||
if ($this->isType($node, $class) && $this->isName($node, $method)) {
|
||||
$activeStaticCall = $staticCall;
|
||||
foreach ($this->staticCallToFunctionByType as $type => $methodNamesToFunctions) {
|
||||
if (! $this->isType($node, $type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($methodNamesToFunctions as $methodName => $function) {
|
||||
if (! $this->isName($node, $methodName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return new FuncCall(new FullyQualified($function), $node->args);
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($this->staticCallToFunction[$activeStaticCall])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$newFunctionName = $this->staticCallToFunction[$activeStaticCall];
|
||||
|
||||
return new FuncCall(new FullyQualified($newFunctionName), $node->args);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
services:
|
||||
Rector\Rector\StaticCall\StaticCallToFunctionRector:
|
||||
Rector\Tests\Rector\StaticCall\StaticCallToFunctionRector\Source\SomeOldStaticClass::render: 'view'
|
||||
Rector\Tests\Rector\StaticCall\StaticCallToFunctionRector\Source\SomeOldStaticClass:
|
||||
render: 'view'
|
||||
|
Loading…
Reference in New Issue
Block a user