Passed
Pull Request — master (#48)
by Aleksei
11:05
created

GroupProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 15
c 1
b 0
f 0
dl 0
loc 28
rs 10

1 Method

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