Passed
Push — master ( 1f27ac...52075a )
by Alexander
04:53 queued 02:24
created

EqualsEmpty   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperator() 0 3 1
A match() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\FilterHandler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Data\Reader\FilterAssert;
9
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
10
11
use function count;
12
13
/**
14
 * `EqualsEmpty` iterable filter handler checks that the item's field value is empty.
15
 */
16
final class EqualsEmpty implements IterableFilterHandlerInterface
17
{
18 104
    public function getOperator(): string
19
    {
20 104
        return \Yiisoft\Data\Reader\Filter\EqualsEmpty::getOperator();
21
    }
22
23 21
    public function match(array|object $item, array $arguments, array $iterableFilterHandlers): bool
24
    {
25 21
        if (count($arguments) !== 1) {
26 4
            throw new InvalidArgumentException('$arguments should contain exactly one element.');
27
        }
28
29 17
        [$field] = $arguments;
30 17
        FilterAssert::fieldIsString($field);
31
32
        /** @var string $field */
33 9
        return empty($item[$field]);
34
    }
35
}
36