mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-17 00:22:24 +00:00
Add remove by name to ArgumentRemoverRector
This commit is contained in:
parent
28b7a6c0cf
commit
963c7bb4c0
|
@ -103,6 +103,11 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
if ($match) {
|
||||
if (isset($match['name'])) {
|
||||
$this->removeByName($node, $position, $match['name']);
|
||||
return;
|
||||
}
|
||||
|
||||
// only argument specific value can be removed
|
||||
if ($node instanceof ClassMethod || ! isset($node->args[$position])) {
|
||||
return;
|
||||
|
@ -123,4 +128,28 @@ CODE_SAMPLE
|
|||
|
||||
return in_array($nodeValue, $values, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|StaticCall|MethodCall $node
|
||||
*/
|
||||
private function removeByName(Node $node, int $position, string $name): void
|
||||
{
|
||||
if ($node instanceof MethodCall || $node instanceof StaticCall) {
|
||||
if (isset($node->args[$position])) {
|
||||
if ($this->isName($node->args[$position], $name)) {
|
||||
unset($node->args[$position]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($node->params[$position])) {
|
||||
if ($this->isName($node->params[$position], $name)) {
|
||||
unset($node->params[$position]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ final class ArgumentAdderRectorTest extends AbstractRectorTestCase
|
|||
return [
|
||||
ContainerBuilder::class => [
|
||||
'compile' => [
|
||||
[
|
||||
0 => [
|
||||
'name' => 'isCompiled',
|
||||
'default_value' => false,
|
||||
],
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Rector\Tests\Rector\Argument\ArgumentRemoverRector;
|
|||
|
||||
use Rector\Rector\Argument\ArgumentRemoverRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\Tests\Rector\Argument\ArgumentRemoverRector\Fixture\RemoveInMiddle;
|
||||
use Rector\Tests\Rector\Argument\ArgumentRemoverRector\Source\Persister;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
|
@ -31,18 +32,20 @@ final class ArgumentRemoverRectorTest extends AbstractRectorTestCase
|
|||
return [
|
||||
Persister::class => [
|
||||
'getSelectJoinColumnSQL' => [
|
||||
4 => null
|
||||
]
|
||||
4 => null,
|
||||
],
|
||||
],
|
||||
Yaml::class => [
|
||||
'parse' => [
|
||||
1 => ['Symfony\Component\Yaml\Yaml::PARSE_KEYS_AS_STRINGS', 'hey', 55, 5.5],
|
||||
],
|
||||
],
|
||||
RemoveInMiddle::class => [
|
||||
'run' => [
|
||||
1 => [
|
||||
'Symfony\Component\Yaml\Yaml::PARSE_KEYS_AS_STRINGS',
|
||||
'hey',
|
||||
55,
|
||||
5.5,
|
||||
]
|
||||
]
|
||||
'name' => 'second',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -4,5 +4,24 @@ namespace Rector\Tests\Rector\Argument\ArgumentRemoverRector\Fixture;
|
|||
|
||||
final class RemoveInMiddle
|
||||
{
|
||||
public function run($first, $second, $third)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Rector\Argument\ArgumentRemoverRector\Fixture;
|
||||
|
||||
final class RemoveInMiddle
|
||||
{
|
||||
public function run($first, $third)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue
Block a user