Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Criteria merge #367

Open
wants to merge 4 commits into
base: 2.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Doctrine\Common\Collections\Expr\Expression;
use Doctrine\Deprecations\Deprecation;

use function array_filter;
use function array_map;
use function array_merge;
use function func_num_args;
use function strtoupper;

Expand Down Expand Up @@ -54,6 +56,20 @@
return self::$expressionBuilder;
}

/**
* Merges two Criteria together.
*
* @return self
*/
public static function merge(Criteria $leftCriteria, Criteria $rightCriteria)

Check warning on line 64 in src/Criteria.php

View check run for this annotation

Codecov / codecov/patch

src/Criteria.php#L64

Added line #L64 was not covered by tests
{
return self::create()
->andWhere(self::expr()->andX(...array_filter([$leftCriteria->getWhereExpression(), $rightCriteria->getWhereExpression()])))
->orderBy(array_merge($leftCriteria->getOrderings(), $rightCriteria->getOrderings()))
->setFirstResult($rightCriteria->getFirstResult() ?? $leftCriteria->getFirstResult())
->setMaxResults($rightCriteria->getMaxResults() ?? $leftCriteria->getFirstResult());

Check warning on line 70 in src/Criteria.php

View check run for this annotation

Codecov / codecov/patch

src/Criteria.php#L66-L70

Added lines #L66 - L70 were not covered by tests
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheDutchScorpion, is it a typo or is it intended?

Suggested change
->setMaxResults($rightCriteria->getMaxResults() ?? $leftCriteria->getFirstResult());
->setMaxResults($rightCriteria->getMaxResults() ?? $leftCriteria->getMaxResults());

}

/**
* Construct a new Criteria.
*
Expand Down