Skip to content

Commit

Permalink
Merge pull request #5 from calmohallag/feature/add_null_operator_support
Browse files Browse the repository at this point in the history
Add null operators support
  • Loading branch information
calmohallag authored Nov 6, 2021
2 parents 3c367ec + 61be396 commit 7359848
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/Criteria/DBALCriteriaVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function execute(Criteria $criteria): void

public function visitAnd(AndFilter $filter): string
{
return '( '. $this->buildExpression($filter->left()) .' AND '. $this->buildExpression($filter->right()) .' )';
return '( ' . $this->buildExpression($filter->left()) . ' AND ' . $this->buildExpression($filter->right()) . ' )';
}

public function visitOr(OrFilter $filter): string
{
return '( '. $this->buildExpression($filter->left()) .' OR '. $this->buildExpression($filter->right()) .' )';
return '( ' . $this->buildExpression($filter->left()) . ' OR ' . $this->buildExpression($filter->right()) . ' )';
}

public function visitFilter(Filter $filter): string
Expand All @@ -71,10 +71,23 @@ public function visitFilter(Filter $filter): string
return $this->mapFieldValue($filter->field()->value())
. ' '
. $this->mapOperator($filter)
. (\in_array($filter->operator()->value(), [FilterOperator::IN, FilterOperator::NOT_IN]) ? ' (' : ' ')
. ':' . $filter->field()->value()
. $this->countParams
. (\in_array($filter->operator()->value(), [FilterOperator::IN, FilterOperator::NOT_IN]) ? ')' : '');
. ' '
. $this->parameterExpression($filter);
}

private function parameterExpression(Filter $filter): string
{
if (\in_array($filter->operator()->value(), [FilterOperator::IS_NULL, FilterOperator::IS_NOT_NULL], true)) {
return '';
}

$parameterName = ':' . $filter->field()->value() . $this->countParams;

if (\in_array($filter->operator()->value(), [FilterOperator::IN, FilterOperator::NOT_IN])) {
return '(' . $parameterName . ')';
}

return $parameterName;
}

private function buildExpression(FilterInterface $filter)
Expand Down

0 comments on commit 7359848

Please sign in to comment.