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

Compare::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
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\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