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

Compare   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A match() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\Handler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Arrays\ArrayHelper;
9
use Yiisoft\Data\Reader\FilterDataValidationHelper;
10
11
use function count;
12
13
abstract class Compare implements IterableHandlerInterface
14
{
15
    abstract protected function compare(mixed $itemValue, mixed $argumentValue): bool;
16
17 165
    public function match(array|object $item, array $arguments, array $filterHandlers): bool
18
    {
19 165
        if (count($arguments) !== 2) {
20 28
            throw new InvalidArgumentException('$arguments should contain exactly two elements.');
21
        }
22
23 137
        [$field, $value] = $arguments;
24 137
        FilterDataValidationHelper::assertFieldIsString($field);
25
26
        /** @var string $field */
27 81
        return $this->compare(ArrayHelper::getValue($item, $field), $value);
28
    }
29
}
30