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

EqualsNullHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
c 0
b 0
f 0
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 7 2
A getFilterClass() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\FilterHandler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Arrays\ArrayHelper;
9
use Yiisoft\Data\Reader\Filter\EqualsNull;
10
use Yiisoft\Data\Reader\FilterInterface;
11
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
12
13
/**
14
 * `EqualsNull` iterable filter handler checks that the item's field value is null.
15
 */
16
final class EqualsNullHandler implements IterableFilterHandlerInterface
17
{
18 143
    public function getFilterClass(): string
19
    {
20 143
        return EqualsNull::class;
21
    }
22
23 10
    public function match(array|object $item, FilterInterface $filter, array $iterableFilterHandlers): bool
24
    {
25 10
        if (!$filter instanceof EqualsNull) {
26 1
            throw new InvalidArgumentException('Incorrect filter.');
27
        }
28
29 9
        return ArrayHelper::getValue($item, $filter->field) === null;
30
    }
31
}
32