diff --git a/rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php b/rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php index 032372b9..5a69c57b 100644 --- a/rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php +++ b/rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php @@ -67,21 +67,21 @@ function query(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder) */ public function refactor(Node $node): ?MethodCall { - $varType = $this->nodeTypeResolver->getType($node->var); - - if (! $varType instanceof ObjectType) { + if (! $this->isNames($node->name, ['select', 'addSelect', 'groupBy', 'addGroupBy'])) { return null; } - if (! $varType->isInstanceOf(DoctrineClass::DBAL_QUERY_BUILDER)->yes()) { + if ($node->isFirstClassCallable()) { return null; } - if (! $this->isNames($node->name, ['select', 'addSelect', 'groupBy', 'addGroupBy'])) { + $varType = $this->nodeTypeResolver->getType($node->var); + + if (! $varType instanceof ObjectType) { return null; } - if ($node->isFirstClassCallable()) { + if (! $varType->isInstanceOf(DoctrineClass::DBAL_QUERY_BUILDER)->yes()) { return null; } diff --git a/rules/Dbal36/Rector/MethodCall/MigrateQueryBuilderResetQueryPartRector.php b/rules/Dbal36/Rector/MethodCall/MigrateQueryBuilderResetQueryPartRector.php index 8c149136..cc9bcd57 100644 --- a/rules/Dbal36/Rector/MethodCall/MigrateQueryBuilderResetQueryPartRector.php +++ b/rules/Dbal36/Rector/MethodCall/MigrateQueryBuilderResetQueryPartRector.php @@ -89,11 +89,11 @@ public function resetQueryPart(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder) */ public function refactor(Node $node): ?Node { - if (! $this->isObjectType($node->var, new ObjectType(DoctrineClass::DBAL_QUERY_BUILDER))) { + if (! $this->isName($node->name, 'resetQueryPart')) { return null; } - if (! $this->isName($node->name, 'resetQueryPart')) { + if (! $this->isObjectType($node->var, new ObjectType(DoctrineClass::DBAL_QUERY_BUILDER))) { return null; } diff --git a/rules/Dbal40/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php b/rules/Dbal40/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php index 5493741d..15a09698 100644 --- a/rules/Dbal40/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php +++ b/rules/Dbal40/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php @@ -81,6 +81,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->isFirstClassCallable()) { + return null; + } + if (! $this->nodeTypeResolver->isObjectType( $node->var, new ObjectType(DoctrineClass::COMPOSITE_EXPRESSION) @@ -88,10 +92,6 @@ public function refactor(Node $node): ?Node return null; } - if ($node->isFirstClassCallable()) { - return null; - } - $node->name = new Identifier('with'); $firstArg = $node->getArgs()[0]; diff --git a/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php b/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php index ffaf4649..eafea2b7 100644 --- a/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php +++ b/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php @@ -96,6 +96,11 @@ public function refactor(Node $node): MethodCall|ClassMethod|Foreach_|null return $this->refactorForeach($node); } + // Change iterate() method calls to toIterable() + if (! $this->isName($node->name, 'iterate')) { + return null; + } + $varType = $this->nodeTypeResolver->getType($node->var); if (! $varType instanceof ObjectType) { @@ -106,11 +111,6 @@ public function refactor(Node $node): MethodCall|ClassMethod|Foreach_|null return null; } - // Change iterate() method calls to toIterable() - if (! $this->isName($node->name, 'iterate')) { - return null; - } - $node->name = new Identifier('toIterable'); return $node; diff --git a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php index aee49b7f..c06aa710 100644 --- a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php +++ b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php @@ -175,21 +175,21 @@ private function getAffectedVariables(ClassMethod $classMethod): iterable private function refactorMethodCall(MethodCall $methodCall): Node|null { - $varType = $this->nodeTypeResolver->getType($methodCall->var); - - if (! $varType instanceof ObjectType) { + if ($methodCall->isFirstClassCallable()) { return null; } - if (! $varType->isInstanceOf('Doctrine\\ORM\\QueryBuilder')->yes()) { + if (! $this->isNames($methodCall->name, ['setParameters'])) { return null; } - if ($methodCall->isFirstClassCallable()) { + $varType = $this->nodeTypeResolver->getType($methodCall->var); + + if (! $varType instanceof ObjectType) { return null; } - if (! $this->isNames($methodCall->name, ['setParameters'])) { + if (! $varType->isInstanceOf('Doctrine\\ORM\\QueryBuilder')->yes()) { return null; }