Passed
Push — master ( cd5f33...085ce3 )
by Aleksei
02:37
created

GroupHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 28
ccs 0
cts 15
cp 0
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B validateArguments() 0 26 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Data\Reader\FilterHandler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Data\Reader\FilterHandlerInterface;
9
use Yiisoft\Yii\Cycle\Data\Reader\QueryBuilderFilterHandler;
10
11
abstract class GroupHandler implements QueryBuilderFilterHandler, FilterHandlerInterface
12
{
13
    protected function validateArguments(array $arguments): void
14
    {
15
        if (count($arguments) === 0) {
16
            throw new InvalidArgumentException('At least one argument should be provided.');
17
        }
18
19
        if (!is_array($arguments[0])) {
20
            throw new InvalidArgumentException('Sub filters is not an array.');
21
        }
22
23
        foreach ($arguments[0] as $subFilter) {
24
            if (!is_array($subFilter)) {
25
                throw new InvalidArgumentException('Sub filter is not an array.');
26
            }
27
28
            if (count($subFilter) === 0) {
29
                throw new InvalidArgumentException('At least operator should be provided.');
30
            }
31
32
            $operator = array_shift($subFilter);
33
            if (!is_string($operator)) {
34
                throw new InvalidArgumentException('Operator is not a string.');
35
            }
36
37
            if ($operator === '') {
38
                throw new InvalidArgumentException('The operator string cannot be empty.');
39
            }
40
        }
41
    }
42
}
43