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

Compare::withValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
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