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

GroupProcessor::validateArguments()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 26
rs 8.4444
cc 8
nc 8
nop 1
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