GroupHandler::validateArguments()   B
last analyzed

Complexity

Conditions 8
Paths 8

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 14
nc 8
nop 1
dl 0
loc 26
ccs 15
cts 15
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
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 11
    protected function validateArguments(array $arguments): void
14
    {
15 11
        if (count($arguments) === 0) {
16 1
            throw new InvalidArgumentException('At least one argument should be provided.');
17
        }
18
19 10
        if (!is_array($arguments[0])) {
20 1
            throw new InvalidArgumentException('Sub filters is not an array.');
21
        }
22
23 9
        foreach ($arguments[0] as $subFilter) {
24 9
            if (!is_array($subFilter)) {
25 1
                throw new InvalidArgumentException('Sub filter is not an array.');
26
            }
27
28 8
            if (count($subFilter) === 0) {
29 1
                throw new InvalidArgumentException('At least operator should be provided.');
30
            }
31
32 7
            $operator = array_shift($subFilter);
33 7
            if (!is_string($operator)) {
34 1
                throw new InvalidArgumentException('Operator is not a string.');
35
            }
36
37 6
            if ($operator === '') {
38 1
                throw new InvalidArgumentException('The operator string cannot be empty.');
39
            }
40
        }
41
    }
42
}
43