Passed
Push — master ( f0feee...3c09de )
by Sergei
12:22
created

AllHandler::match()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\FilterHandler;
6
7
use LogicException;
8
use Yiisoft\Data\Reader\Filter\All;
9
use Yiisoft\Data\Reader\FilterInterface;
10
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
11
12
/**
13
 * `All` iterable filter handler allows combining multiple sub-filters.
14
 * The filter matches only if all the sub-filters match.
15
 */
16
final class AllHandler implements IterableFilterHandlerInterface
17
{
18 143
    public function getFilterClass(): string
19
    {
20 143
        return All::class;
21
    }
22
23 9
    public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool
24
    {
25
        /** @var All $filter */
26
27 9
        foreach ($filter->getFilters() as $subFilter) {
0 ignored issues
show
Bug introduced by
The method getFilters() does not exist on Yiisoft\Data\Reader\FilterInterface. It seems like you code against a sub-type of Yiisoft\Data\Reader\FilterInterface such as Yiisoft\Data\Reader\Filter\Group. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        foreach ($filter->/** @scrutinizer ignore-call */ getFilters() as $subFilter) {
Loading history...
28 9
            $filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null;
29 9
            if ($filterHandler === null) {
30 1
                throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class));
31
            }
32 8
            if (!$filterHandler->match($item, $subFilter, $iterableFilterHandlers)) {
33 6
                return false;
34
            }
35
        }
36
37 4
        return true;
38
    }
39
}
40