Passed
Pull Request — master (#165)
by Alexander
05:02 queued 02:25
created

NotHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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