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

Compare   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getField() 0 3 1
A withValue() 0 5 1
A getValue() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Filter;
6
7
use DateTimeInterface;
8
use Yiisoft\Data\Reader\FilterInterface;
9
10
/**
11
 * `Compare` filter is a base class that defines a criteria for comparing field value with a given value.
12
 */
13
abstract class Compare implements FilterInterface
14
{
15
    /**
16
     * @param string $field Name of the field to compare.
17
     * @param bool|DateTimeInterface|float|int|string $value Value to compare to.
18
     */
19 97
    public function __construct(
20
        private readonly string $field,
21
        private bool|DateTimeInterface|float|int|string $value,
22
    ) {
23 97
    }
24
25 109
    public function getField(): string
26
    {
27 109
        return $this->field;
28
    }
29
30 109
    public function getValue(): float|DateTimeInterface|bool|int|string
31
    {
32 109
        return $this->value;
33
    }
34
35
    /**
36
     * @param bool|DateTimeInterface|float|int|string $value Value to compare to.
37
     */
38 2
    final public function withValue(bool|DateTimeInterface|float|int|string $value): static
39
    {
40 2
        $new = clone $this;
41 2
        $new->value = $value;
42 2
        return $new;
43
    }
44
}
45