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

NotHandler::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
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\Not;
10
use Yiisoft\Data\Reader\FilterInterface;
11
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
12
13
use function sprintf;
14
15
/**
16
 * `Not` iterable filter handler negates another filter.
17
 */
18
final class NotHandler implements IterableFilterHandlerInterface
19
{
20 143
    public function getFilterClass(): string
21
    {
22 143
        return Not::class;
23
    }
24
25 6
    public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool
26
    {
27
        /** @var Not $filter */
28
29 6
        $filterHandler = $iterableFilterHandlers[$filter->filter::class] ?? null;
30 6
        if ($filterHandler === null) {
31 1
            throw new LogicException(sprintf('Filter "%s" is not supported.', $filter->filter::class));
32
        }
33 5
        return !$filterHandler->match($item, $filter->filter, $iterableFilterHandlers);
34
    }
35
}
36