Skip to content

Commit 08ab3d1

Browse files
committed
Updated filters management
1 parent 2f6588b commit 08ab3d1

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Filter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Kiboko\Component\Flow\Magento2;
4+
5+
class Filter
6+
{
7+
public function __construct(
8+
public string $field,
9+
public string $conditionType,
10+
public string $value,
11+
) {
12+
}
13+
}

src/FilterGroup.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22

33
namespace Kiboko\Component\Flow\Magento2;
44

5-
use phpDocumentor\Reflection\Types\This;
6-
75
class FilterGroup
86
{
97
private array $filters = [];
108

11-
public function asArray(): array
9+
public function withFilter(Filter $filter): self
1210
{
13-
return $this->filters;
11+
$this->filters[] = [
12+
'field' => $filter->field,
13+
'value' => $filter->value,
14+
'condition_type' => $filter->conditionType,
15+
];
16+
17+
return $this;
1418
}
1519

16-
public function withFilter(string $field, string $operator, mixed $value): self
20+
public function withFilters(Filter ...$filters): self
1721
{
18-
$this->filters[] = [
19-
'field' => $field,
20-
'value' => $value,
21-
'condition_type' => $operator,
22-
];
22+
array_walk($filters, fn (Filter $filter) => $this->filters[] = [
23+
'field' => $filter->field,
24+
'value' => $filter->value,
25+
'condition_type' => $filter->conditionType,
26+
]);
2327

2428
return $this;
2529
}
@@ -35,11 +39,11 @@ public function compileFilters(int $groupIndex = 0): array
3539

3640
public function greaterThan(string $field, mixed $value): self
3741
{
38-
return $this->withFilter($field, 'gt', $value);
42+
return $this->withFilter(new Filter($field, 'gt', $value));
3943
}
4044

4145
public function greaterThanEqual(string $field, mixed $value): self
4246
{
43-
return $this->withFilter($field, 'gteq', $value);
47+
return $this->withFilter(new Filter($field, 'gteq', $value));
4448
}
4549
}

0 commit comments

Comments
 (0)