FlattenSingleArgumentBinaryOperation.php 863 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Files\Search\QueryOptimizer;
  7. use OCP\Files\Search\ISearchBinaryOperator;
  8. use OCP\Files\Search\ISearchOperator;
  9. /**
  10. * replace single argument AND and OR operations with their single argument
  11. */
  12. class FlattenSingleArgumentBinaryOperation extends ReplacingOptimizerStep {
  13. public function processOperator(ISearchOperator &$operator): bool {
  14. parent::processOperator($operator);
  15. if (
  16. $operator instanceof ISearchBinaryOperator &&
  17. count($operator->getArguments()) === 1 &&
  18. (
  19. $operator->getType() === ISearchBinaryOperator::OPERATOR_OR ||
  20. $operator->getType() === ISearchBinaryOperator::OPERATOR_AND
  21. )
  22. ) {
  23. $operator = $operator->getArguments()[0];
  24. return true;
  25. }
  26. return false;
  27. }
  28. }