Passed
Pull Request — master (#165)
by Sergei
02:36
created

InHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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