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

EqualsHandler::getFilterClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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