Passed
Push — master ( f06de2...0ad1df )
by Alexander
02:43 queued 01:20
created

GroupProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A match() 0 19 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Yiisoft\Data\Reader\Iterable\Processor;
5
6
7
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
8
9
abstract class GroupProcessor implements IterableProcessorInterface, FilterProcessorInterface
10
{
11
    abstract protected function checkResults(array $result): bool;
12
13
    abstract protected function checkResult($result): ?bool;
14
15
    /**
16
     * PHP variable specific execute
17
     */
18 2
    public function match(array $item, array $arguments, array $filterProcessors): bool
19
    {
20 2
        $results = [];
21 2
        foreach ($arguments[0] as $subFilter) {
22 2
            $operation = array_shift($subFilter);
23
24 2
            $processor = $filterProcessors[$operation] ?? null;
25 2
            if ($processor === null) {
26
                throw new \RuntimeException(sprintf('Operation "%s" is not supported', $operation));
27
            }
28
            /* @var $processor IterableProcessorInterface */
29 2
            $result = $processor->match($item, $subFilter, $filterProcessors);
30 2
            if(is_bool($this->checkResult($result))) {
31 2
                return $result;
32
            }
33 2
            $results[] = $result;
34
        }
35
36 2
        return $this->checkResults($results);
37
    }
38
39
40
}
41