Passed
Pull Request — master (#173)
by Alexander
14:57 queued 12:22
created

ILikeHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
c 1
b 1
f 0
dl 0
loc 14
ccs 5
cts 5
cp 1
rs 10
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\ILike;
9
use Yiisoft\Data\Reader\FilterInterface;
10
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
11
12
use function is_string;
13
14
/**
15
 * `ILike` iterable filter handler ensures that the field value is like-match to a given value (case-insensitive).
16
 */
17
final class ILikeHandler implements IterableFilterHandlerInterface
18
{
19 144
    public function getFilterClass(): string
20
    {
21 144
        return ILike::class;
22
    }
23
24 6
    public function match(object|array $item, FilterInterface $filter, array $iterableFilterHandlers): bool
25
    {
26
        /** @var ILike $filter */
27
28 6
        $itemValue = ArrayHelper::getValue($item, $filter->getField());
29
30 6
        return is_string($itemValue) && mb_stripos($itemValue, $filter->getValue()) !== false;
31
    }
32
}
33