Passed
Push — master ( 951d77...1f27ac )
by Alexander
02:35
created

EqualsEmpty::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\Handler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Data\Reader\FilterDataValidationHelper;
9
10
use function count;
11
12
final class EqualsEmpty implements IterableHandlerInterface
13
{
14 104
    public function getOperator(): string
15
    {
16 104
        return \Yiisoft\Data\Reader\Filter\EqualsEmpty::getOperator();
17
    }
18
19 21
    public function match(array|object $item, array $arguments, array $filterHandlers): bool
20
    {
21 21
        if (count($arguments) !== 1) {
22 4
            throw new InvalidArgumentException('$arguments should contain exactly one element.');
23
        }
24
25 17
        [$field] = $arguments;
26 17
        FilterDataValidationHelper::assertFieldIsString($field);
27
28
        /** @var string $field */
29 9
        return empty($item[$field]);
30
    }
31
}
32