Passed
Push — master ( f0feee...3c09de )
by Sergei
12:22
created

InHandler::match()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Iterable\FilterHandler;
6
7
use Yiisoft\Arrays\ArrayHelper;
8
use Yiisoft\Data\Reader\Filter\In;
9
use Yiisoft\Data\Reader\FilterInterface;
10
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
11
12
use function in_array;
13
14
/**
15
 * `In` iterable filter handler ensures that the field value matches one of the value provided.
16
 */
17
final class InHandler implements IterableFilterHandlerInterface
18
{
19 143
    public function getFilterClass(): string
20
    {
21 143
        return In::class;
22
    }
23
24 5
    public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool
25
    {
26
        /** @var In $filter */
27
28 5
        $itemValue = ArrayHelper::getValue($item, $filter->getField());
29 5
        $argumentValue = $filter->getValues();
30
31 5
        return in_array($itemValue, $argumentValue);
32
    }
33
}
34