mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
Merge pull request #717 from rectorphp/func-rename
Fix inlining ofr changed FuncCall args [closes #624]
This commit is contained in:
commit
91797daad2
@ -4,7 +4,6 @@ namespace Rector\Rector\Function_;
|
|||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr\FuncCall;
|
use PhpParser\Node\Expr\FuncCall;
|
||||||
use PhpParser\Node\Name;
|
|
||||||
use PhpParser\Node\Name\FullyQualified;
|
use PhpParser\Node\Name\FullyQualified;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||||
@ -53,21 +52,15 @@ final class FunctionReplaceRector extends AbstractRector
|
|||||||
*/
|
*/
|
||||||
public function refactor(Node $node): ?Node
|
public function refactor(Node $node): ?Node
|
||||||
{
|
{
|
||||||
// anonymous function
|
$functionName = $this->getName($node);
|
||||||
if (! $node->name instanceof Name) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$functionName = $node->name->toString();
|
|
||||||
if (! isset($this->oldFunctionToNewFunction[$functionName])) {
|
if (! isset($this->oldFunctionToNewFunction[$functionName])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newFunctionName = $this->oldFunctionToNewFunction[$functionName];
|
$newFunctionName = $this->oldFunctionToNewFunction[$functionName];
|
||||||
|
|
||||||
$functCallNode = new FuncCall(new FullyQualified($newFunctionName));
|
$node->name = new FullyQualified($newFunctionName);
|
||||||
$functCallNode->args = $node->args;
|
|
||||||
|
|
||||||
return $functCallNode;
|
return $node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Tests\Rector\Function_\FunctionReplaceRector\Wrong;
|
||||||
|
|
||||||
|
class SomeClass
|
||||||
|
{
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this->setDescription(\Safe\sprintf(
|
||||||
|
'Splits monorepo packages to standalone repositories as defined in "%s" section of "%s" config.',
|
||||||
|
'parameters > directories_to_repositories',
|
||||||
|
'monorepo-builder.yml'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ final class FunctionReplaceRectorTest extends AbstractRectorTestCase
|
|||||||
public function provideWrongToFixedFiles(): Iterator
|
public function provideWrongToFixedFiles(): Iterator
|
||||||
{
|
{
|
||||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||||
|
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function provideConfig(): string
|
protected function provideConfig(): string
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Tests\Rector\Function_\FunctionReplaceRector\Wrong;
|
||||||
|
|
||||||
|
class SomeClass
|
||||||
|
{
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this->setDescription(sprintf(
|
||||||
|
'Splits monorepo packages to standalone repositories as defined in "%s" section of "%s" config.',
|
||||||
|
'parameters > directories_to_repositories',
|
||||||
|
'monorepo-builder.yml'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
Rector\Rector\Function_\FunctionReplaceRector:
|
Rector\Rector\Function_\FunctionReplaceRector:
|
||||||
'view': 'Laravel\Templating\render'
|
view: 'Laravel\Templating\render'
|
||||||
|
sprintf: 'Safe\sprintf'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user