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

LikeHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 14
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilterClass() 0 3 1
A match() 0 7 2
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\Like;
9
use Yiisoft\Data\Reader\FilterInterface;
10
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
11
12
use function is_string;
13
use function stripos;
14
15
/**
16
 * `Like` iterable filter handler ensures that the field value is like-match to a given value.
17
 */
18
final class LikeHandler implements IterableFilterHandlerInterface
19
{
20 143
    public function getFilterClass(): string
21
    {
22 143
        return Like::class;
23
    }
24
25 6
    public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool
26
    {
27
        /** @var Like $filter */
28
29 6
        $itemValue = ArrayHelper::getValue($item, $filter->getField());
30
31 6
        return is_string($itemValue) && stripos($itemValue, $filter->getValue()) !== false;
32
    }
33
}
34