mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
[PHP] RemoveReferenceFromCallRector
This commit is contained in:
parent
62c3f3638b
commit
2c93adc0d9
@ -1,3 +1,4 @@
|
||||
services:
|
||||
Rector\Rector\Function_\FunctionReplaceRector:
|
||||
mysqli_param_count: 'mysqli_stmt_param_count'
|
||||
Rector\Php\Rector\FuncCall\RemoveReferenceFromCallRector: ~
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user