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

GroupProcessor::match()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0092

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 3
dl 0
loc 19
ccs 11
cts 12
cp 0.9167
crap 4.0092
rs 9.9
c 0
b 0
f 0
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