Passed
Pull Request — master (#165)
by Sergei
02:36
created

AnyHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilterClass() 0 3 1
A match() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\FilterHandler;
6
7
use InvalidArgumentException;
8
use LogicException;
9
use Yiisoft\Data\Reader\Filter\Any;
10
use Yiisoft\Data\Reader\FilterInterface;
11
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
12
13
/**
14
 * `Any` iterable filter handler allows combining multiple sub-filters.
15
 * The filter matches if any of the sub-filters match.
16
 */
17
final class AnyHandler implements IterableFilterHandlerInterface
18
{
19 143
    public function getFilterClass(): string
20
    {
21 143
        return Any::class;
22
    }
23
24 8
    public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool
25
    {
26
        /** @var Any $filter */
27
28 8
        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

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