[PHP] RemoveReferenceFromCallRector

This commit is contained in:
Tomas Votruba 2019-02-20 01:04:27 +01:00
parent 62c3f3638b
commit 2c93adc0d9
4 changed files with 102 additions and 0 deletions

View File

@ -1,3 +1,4 @@
services:
Rector\Rector\Function_\FunctionReplaceRector:
mysqli_param_count: 'mysqli_stmt_param_count'
Rector\Php\Rector\FuncCall\RemoveReferenceFromCallRector: ~

View File

@ -0,0 +1,61 @@
<?php declare(strict_types=1);
namespace Rector\Php\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
final class RemoveReferenceFromCallRector extends AbstractRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Remove & from function and method calls', [
new CodeSample(
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($one)
{
return strlen(&$one);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
final class SomeClass
{
public function run($one)
{
return strlen($one);
}
}
CODE_SAMPLE
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
{
foreach ($node->args as $nodeArg) {
if ($nodeArg->byRef) {
$nodeArg->byRef = false;
}
}
return $node;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Rector\Php\Tests\Rector\FuncCall\RemoveReferenceFromCallRector\Fixture;
function removeReference($one)
{
return strlen(&$one);
}
?>
-----
<?php
namespace Rector\Php\Tests\Rector\FuncCall\RemoveReferenceFromCallRector\Fixture;
function removeReference($one)
{
return strlen($one);
}
?>

View File

@ -0,0 +1,19 @@
<?php declare(strict_types=1);
namespace Rector\Php\Tests\Rector\FuncCall\RemoveReferenceFromCallRector;
use Rector\Php\Rector\FuncCall\RemoveReferenceFromCallRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class RemoveReferenceFromCallRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFilesWithoutAutoload([__DIR__ . '/Fixture/fixture.php.inc']);
}
protected function getRectorClass(): string
{
return RemoveReferenceFromCallRector::class;
}
}