add relatedTypesAndMethods property to collect defluented methods

This commit is contained in:
TomasVotruba 2018-01-13 23:11:21 +01:00
parent 4cff4cede5
commit 4ca2743a29
2 changed files with 12 additions and 3 deletions

View File

@ -3,15 +3,18 @@
namespace Rector\Rector\Dynamic; namespace Rector\Rector\Dynamic;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\NodeTraverser;
use Rector\Node\Attribute; use Rector\Node\Attribute;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
final class FluentReplaceRector extends AbstractRector final class FluentReplaceRector extends AbstractRector
{ {
/**
* @var string[][]
*/
private $relatedTypesAndMethods;
public function isCandidate(Node $node): bool public function isCandidate(Node $node): bool
{ {
if (! $node instanceof Return_) { if (! $node instanceof Return_) {
@ -30,6 +33,12 @@ final class FluentReplaceRector extends AbstractRector
public function refactor(Node $node): ?Node public function refactor(Node $node): ?Node
{ {
$this->removeNode = true; $this->removeNode = true;
$className = $node->getAttribute(Attribute::CLASS_NAME);
$methodName = $node->getAttribute(Attribute::METHOD_NAME);
$this->relatedTypesAndMethods[$className][] = $methodName;
return null; return null;
} }
} }

View File

@ -26,7 +26,7 @@ class ActionClass
{ {
$this->someClass = new SomeClass(); $this->someClass = new SomeClass();
$this->someClass->someFunction() $this->someClass->someFunction();
$this->someClass->otherFunction(); $this->someClass->otherFunction();
} }
} }