Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
7 / 7 |
Aggregate | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
7 / 7 |
check | |
100.00% |
1 / 1 |
3 | |
100.00% |
3 / 3 |
|||
onlyOneEntry | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiFilterRequest\Filters; |
4 | |
5 | use Qmp\Laravel\ApiFilterRequest\Filters; |
6 | |
7 | class Aggregate extends AbstractFilter |
8 | { |
9 | const COUNT = 'count'; |
10 | const MAX = 'max'; |
11 | const MIN = 'min'; |
12 | const AVG = 'avg'; |
13 | const SUM = 'sum'; |
14 | |
15 | /** |
16 | * @param $data |
17 | * @return bool |
18 | */ |
19 | public function check($data) |
20 | { |
21 | return $this->isArray($data) |
22 | && $this->onlyOneEntry($data) |
23 | && $this->eachKeyOfArrayIsEnum($data, [self::COUNT, self::MAX, self::MIN, self::AVG, self::SUM]); |
24 | } |
25 | |
26 | /** |
27 | * @param $data |
28 | * @return bool |
29 | */ |
30 | protected function onlyOneEntry($data) |
31 | { |
32 | if (!(count($data) === 1)) { |
33 | $this->addError('Nb of entry must exactly be one : ' . var_export($data, true)); |
34 | return false; |
35 | }; |
36 | |
37 | return true; |
38 | } |
39 | } |