Skip to content

Commit

Permalink
throw BadRequestException when a wrong operator set to a filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ngabor84 committed May 23, 2017
1 parent d1011aa commit e7708e4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/BuilderParamsApplierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use LumenApiQueryParser\Params\Filter;
use LumenApiQueryParser\Params\RequestParamsInterface;
use LumenApiQueryParser\Params\Sort;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

trait BuilderParamsApplierTrait
{
Expand Down Expand Up @@ -70,7 +71,6 @@ protected function applyFilter(Builder $query, Filter $filter): void
$clauseOperator = 'LIKE';
break;
case 'eq':
default:
$clauseOperator = '=';
break;
case 'ne':
Expand All @@ -88,12 +88,12 @@ protected function applyFilter(Builder $query, Filter $filter): void
case 'le':
$clauseOperator = '<=';
break;
default:
throw new BadRequestHttpException(sprintf('Not allowed operator: %s', $operator));
}

if ($operator === 'in') {
call_user_func_array([$query, 'whereIn'], [
$field, explode('|', $value)
]);
$query->whereIn($filter, explode('|', $value));
} else {
call_user_func_array([$query, $method], [
$field, $clauseOperator, $value
Expand Down

0 comments on commit e7708e4

Please sign in to comment.