Skip to content

Commit

Permalink
fix: add filter without key
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Apr 9, 2024
1 parent 958ca86 commit ac95e5e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Dto/Search/Query/SearchQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SearchQueryBuilder
*/
private array $sort = [];
/**
* @var array<string,Filter>
* @var array<Filter>
*/
private array $filter = [];

Expand Down Expand Up @@ -94,13 +94,17 @@ public function sort(Criteria ...$criteriaList): static
public function filter(Filter ...$filterList): static
{
foreach ($filterList as $filter) {
if (isset($this->filter[$filter->key])) {
throw new \InvalidArgumentException(
'filter key "' . $filter->key .
if ($filter->key !== null) {
foreach ($this->filter as $existingFilter) {
if ($existingFilter->key === $filter->key) {
throw new \InvalidArgumentException(
'filter key "' . $filter->key .
'" already exists'
);
);
}
}
}
$this->filter[$filter->key] = $filter;
$this->filter[] = $filter;
}
return $this;
}
Expand Down Expand Up @@ -140,7 +144,7 @@ public function build(): SearchQuery
offset: $this->offset,
limit: $this->limit,
sort: $this->sort,
filter: array_values($this->filter),
filter: $this->filter,
facets: array_values($this->facets),
defaultQueryOperator: $this->defaultQueryOperator
);
Expand Down

0 comments on commit ac95e5e

Please sign in to comment.