Passed
Pull Request — master (#165)
by Alexander
05:02 queued 02:25
created

LikeHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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