Fix bug when calling toString in Variable

This commit is contained in:
Gabriel Caruso 2018-01-22 23:38:27 -02:00
parent 5e4b512f45
commit 5f8df78ce7
3 changed files with 29 additions and 3 deletions

View File

@ -3,9 +3,11 @@
namespace Rector\Rector\Contrib\PHPUnit\SpecificMethod;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use Rector\NodeAnalyzer\MethodCallAnalyzer;
use Rector\NodeChanger\IdentifierRenamer;
use Rector\Rector\AbstractPHPUnitRector;
@ -51,7 +53,7 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
}
$firstArgumentValue = $node->args[0]->value;
if (! $firstArgumentValue instanceof FuncCall) {
if (! $this->isNamedFunction($firstArgumentValue)) {
return false;
}
@ -97,4 +99,14 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
$this->identifierRenamer->renameNode($methodCallNode, 'assertContains');
}
}
private function isNamedFunction(Expr $node): bool
{
if (! $node instanceof FuncCall) {
return false;
}
$functionName = $node->name;
return $functionName instanceof Name;
}
}

View File

@ -3,8 +3,10 @@
namespace Rector\Rector\Contrib\PHPUnit\SpecificMethod;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name;
use Rector\Node\NodeFactory;
use Rector\NodeAnalyzer\MethodCallAnalyzer;
use Rector\NodeChanger\IdentifierRenamer;
@ -90,7 +92,7 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
$methodCallNode = $node;
$firstArgumentValue = $methodCallNode->args[0]->value;
if (! $firstArgumentValue instanceof FuncCall) {
if (! $this->isNamedFunction($firstArgumentValue)) {
return false;
}
@ -125,4 +127,14 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
$argument,
], $oldArguments);
}
private function isNamedFunction(Expr $node): bool
{
if (! $node instanceof FuncCall) {
return false;
}
$functionName = $node->name;
return $functionName instanceof Name;
}
}

View File

@ -171,7 +171,9 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractPHPUnitRector
private function resolveFunctionName(Node $node): ?string
{
if ($node instanceof FuncCall) {
if ($node instanceof FuncCall
&& $node->name instanceof Name
) {
/** @var Name $nameNode */
$nameNode = $node->name;