Passed
Push — master ( 046edc...7f8fa3 )
by Alexander
02:26
created

GroupProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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