handle Return_ in own method

This commit is contained in:
TomasVotruba 2018-01-13 23:11:59 +01:00
parent 4ca2743a29
commit 3f1048936e

View File

@ -17,28 +17,35 @@ final class FluentReplaceRector extends AbstractRector
public function isCandidate(Node $node): bool
{
if (! $node instanceof Return_) {
return false;
if ($node instanceof Return_) {
$returnExpr = $node->expr;
if (! $returnExpr instanceof Variable) {
return false;
}
return $returnExpr->name === 'this';
}
$returnExpr = $node->expr;
if (! $returnExpr instanceof Variable) {
return false;
}
return $returnExpr->name === 'this';
return false;
}
/**
* @param Return_ $node
*/
public function refactor(Node $node): ?Node
{
$this->removeNode = true;
if ($node instanceof Return_) {
$this->removeNode = true;
$className = $node->getAttribute(Attribute::CLASS_NAME);
$methodName = $node->getAttribute(Attribute::METHOD_NAME);
$className = $node->getAttribute(Attribute::CLASS_NAME);
$methodName = $node->getAttribute(Attribute::METHOD_NAME);
$this->relatedTypesAndMethods[$className][] = $methodName;
$this->relatedTypesAndMethods[$className][] = $methodName;
return null;
return null;
}
return $node;
}
}