Passed
Push — master ( 4f0280...b89b05 )
by Alexander
01:15
created

Not::match()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7.0957

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 7
nop 3
dl 0
loc 22
ccs 14
cts 16
cp 0.875
crap 7.0957
rs 8.8333
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Yiisoft\Data\Reader\Iterable\Processor;
5
6
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
7
8
class Not implements IterableProcessorInterface, FilterProcessorInterface
9
{
10
11 60
    public function getOperator(): string
12
    {
13 60
        return \YiiSoft\Data\Reader\Filter\Not::getOperator();
14
    }
15
16 5
    public function match(array $item, array $arguments, array $filterProcessors): bool
17
    {
18 5
        if (count($arguments) !== 1) {
19 1
            throw new \RuntimeException('$arguments should contain exactly one element!');
20 4
        } elseif (!is_array($arguments[0])) {
21 1
            throw new \RuntimeException('$arguments[0] is not an array!');
22 3
        } elseif (count($arguments[0]) < 1) {
23 1
            throw new \RuntimeException('At least operator should be provided!');
24
        }
25 2
        $operator = array_shift($arguments[0]);
26 2
        if (!is_string($operator)) {
27
            throw new \RuntimeException('Operator is not a string!');
28 2
        } elseif (strlen($operator) === 0) {
29 1
            throw new \RuntimeException('The operator string cannot be empty!');
30
        }
31
32 1
        $processor = $filterProcessors[$operator] ?? null;
33 1
        if ($processor === null) {
34
            throw new \RuntimeException(sprintf('"%s" operator is not supported!', $operator));
35
        }
36
        /* @var $processor IterableProcessorInterface */
37 1
        return !$processor->match($item, $arguments[0], $filterProcessors);
38
    }
39
40
}
41