Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\Dbal40\Rector\StmtsAwareInterface\ExecuteQueryParamsToBindValueRector\Fixture;

use Rector\Doctrine\Tests\Dbal40\Rector\StmtsAwareInterface\ExecuteQueryParamsToBindValueRector\Source\Statement;

final class SkipDifferentObjectWithExecute
{
public function run(Statement $statement, array $params): void
{
$result = $statement->executeQuery($params);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\Dbal40\Rector\StmtsAwareInterface\ExecuteQueryParamsToBindValueRector\Source;

class Statement
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace Rector\Doctrine\Dbal40\Rector\StmtsAwareInterface;

use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Plus;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Plus;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\NodeFinder;
use PHPStan\Type\ObjectType;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -72,17 +73,21 @@ public function refactor(Node $node): ?StmtsAwareInterface
$nodeFinder = new NodeFinder();

$hasChanged = false;

$objectType = new ObjectType('Doctrine\DBAL\Statement');
foreach ((array) $node->stmts as $key => $stmt) {
if (! $stmt instanceof Expression) {
continue;
}

$executeQueryMethodCall = $nodeFinder->findFirst($stmt, function (Node $node): bool {
$executeQueryMethodCall = $nodeFinder->findFirst($stmt, function (Node $node) use ($objectType): bool {
if (! $node instanceof MethodCall) {
return false;
}

if (! $this->isObjectType($node->var, $objectType)) {
return false;
}

if (! $this->isName($node->name, 'executeQuery')) {
return false;
}
Expand All @@ -95,7 +100,8 @@ public function refactor(Node $node): ?StmtsAwareInterface
}

// remove args
$stmtsExpr = $executeQueryMethodCall->getArgs()[0]->value;
$stmtsExpr = $executeQueryMethodCall->getArgs()[0]
->value;
$executeQueryMethodCall->args = [];

$hasChanged = true;
Expand Down