22
33namespace Kiboko \Component \Flow \Magento2 ;
44
5- use phpDocumentor \Reflection \Types \This ;
6-
75class 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