Passed
Pull Request — master (#165)
by Sergei
03:21 queued 42s
created

NotHandler::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 3
nop 3
crap 3
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 7
    public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool
26
    {
27 7
        if (!$filter instanceof Not) {
28 1
            throw new InvalidArgumentException('Incorrect filter.');
29
        }
30
31 6
        $filterHandler = $iterableFilterHandlers[$filter->filter::class] ?? null;
32 6
        if ($filterHandler === null) {
33 1
            throw new LogicException(sprintf('Filter "%s" is not supported.', $filter->filter::class));
34
        }
35 5
        return !$filterHandler->match($item, $filter->filter, $iterableFilterHandlers);
36
    }
37
}
38