Collect method call renames for future usage (#6149)

This commit is contained in:
Michal Lulco 2021-04-15 22:44:58 +02:00 committed by GitHub
parent 27f3544e8e
commit be2a54e0b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 41 deletions

View File

@ -280,6 +280,7 @@ parameters:
paths:
- bin/rector.php
- rules/Php70/Rector/FuncCall/MultiDirnameRector.php
- src/Application/FileProcessor/PhpFileProcessor.php
-
message: '#Function "class_exists\(\)" cannot be used/left in the code#'
@ -513,11 +514,6 @@ parameters:
paths:
- src/PhpParser/Parser/FunctionLikeParser.php
-
message: '#Unreachable statement \- code above always terminates#'
paths:
- src/Application/FileProcessor/PhpFileProcessor.php
-
message: '#Property with protected modifier is not allowed\. Use interface contract method instead#'
paths:

View File

@ -0,0 +1,26 @@
<?php
namespace Rector\Renaming\Collector;
use Rector\Renaming\Contract\MethodCallRenameInterface;
final class MethodCallRenameCollector
{
/**
* @var MethodCallRenameInterface[]
*/
private $methodCallRenames = [];
public function addMethodCallRename(MethodCallRenameInterface $methodCallRename): void
{
$this->methodCallRenames[] = $methodCallRename;
}
/**
* @return MethodCallRenameInterface[]
*/
public function getMethodCallRenames(): array
{
return $this->methodCallRenames;
}
}

View File

@ -17,6 +17,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\NodeManipulator\ClassManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Renaming\Collector\MethodCallRenameCollector;
use Rector\Renaming\Contract\MethodCallRenameInterface;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey;
@ -44,9 +45,15 @@ final class RenameMethodRector extends AbstractRector implements ConfigurableRec
*/
private $classManipulator;
public function __construct(ClassManipulator $classManipulator)
/**
* @var MethodCallRenameCollector
*/
private $methodCallRenameCollector;
public function __construct(ClassManipulator $classManipulator, MethodCallRenameCollector $methodCallRenameCollector)
{
$this->classManipulator = $classManipulator;
$this->methodCallRenameCollector = $methodCallRenameCollector;
}
public function getRuleDefinition(): RuleDefinition
@ -130,6 +137,10 @@ CODE_SAMPLE
Assert::allIsInstanceOf($methodCallRenames, MethodCallRenameInterface::class);
$this->methodCallRenames = $methodCallRenames;
foreach ($methodCallRenames as $methodCallRename) {
$this->methodCallRenameCollector->addMethodCallRename($methodCallRename);
}
}
/**