diff --git a/src/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector.php b/src/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector.php index 4355ca2ed..7fb06c53e 100644 --- a/src/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector.php +++ b/src/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Empty_; +use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\LNumber; @@ -75,6 +76,21 @@ public function refactor(Node $node): ?Node return null; } + if ($args[0]->unpack === true) { + // In this case, the code looks like this: $query->logicalAnd(...$constraints); + $parentIfStatement = $this->betterNodeFinder->findParentType($node, If_::class); + // the if should not contain a count, otherwise it is probably migrated already + if ($parentIfStatement instanceof If_ && $parentIfStatement->cond instanceof Identical) { + $comparison = $parentIfStatement->cond; + if ($comparison->left instanceof FuncCall && $this->isName($comparison->left, 'count')) { + return null; + } + if ($comparison->right instanceof FuncCall && $this->isName($comparison->right, 'count')) { + return null; + } + } + } + $firstArgument = $args[0]->value; if ($firstArgument instanceof Variable) { diff --git a/tests/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector/Fixture/query_logical_and_with_variables_as_arguments_migrated.php.inc b/tests/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector/Fixture/query_logical_and_with_variables_as_arguments_migrated.php.inc new file mode 100644 index 000000000..18f2c6b9f --- /dev/null +++ b/tests/Rector/v12/v0/typo3/HardenMethodSignatureOfLogicalAndAndLogicalOrRector/Fixture/query_logical_and_with_variables_as_arguments_migrated.php.inc @@ -0,0 +1,87 @@ +createQuery(); + if (count($constraints) === 1) { + $query->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $query->matching($query->logicalAnd(...$constraints)); + } + } + + public function findAllForListWithDifferentQueryVariableName() + { + $constraints = []; + $q = $this->createQuery(); + if (count($constraints) === 1) { + $q->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $q->matching($q->logicalAnd(...$constraints)); + } + } + + public function findAllForListWithLogicalOr() + { + $constraints = []; + $q = $this->createQuery(); + if (count($constraints) === 1) { + $q->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $q->matching($q->logicalOr(...$constraints)); + } + } +} + +?> +----- +createQuery(); + if (count($constraints) === 1) { + $query->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $query->matching($query->logicalAnd(...$constraints)); + } + } + + public function findAllForListWithDifferentQueryVariableName() + { + $constraints = []; + $q = $this->createQuery(); + if (count($constraints) === 1) { + $q->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $q->matching($q->logicalAnd(...$constraints)); + } + } + + public function findAllForListWithLogicalOr() + { + $constraints = []; + $q = $this->createQuery(); + if (count($constraints) === 1) { + $q->matching(reset($constraints)); + } elseif (count($constraints) >= 2) { + $q->matching($q->logicalOr(...$constraints)); + } + } +} + +?>