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

Compare::getValue()   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\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
 * The operator is defined by child classes.
13
 */
14
abstract class Compare implements FilterInterface
15
{
16
    /**
17
     * @param string $field Name of the field to compare.
18
     * @param bool|DateTimeInterface|float|int|string $value Value to compare to.
19
     */
20 97
    public function __construct(
21
        public readonly string $field,
22
        private bool|DateTimeInterface|float|int|string $value,
23
    ) {
24 97
    }
25
26 109
    public function getValue(): float|DateTimeInterface|bool|int|string
27
    {
28 109
        return $this->value;
29
    }
30
31
    /**
32
     * @param bool|DateTimeInterface|float|int|string $value Value to compare to.
33
     */
34 2
    final public function withValue(bool|DateTimeInterface|float|int|string $value): static
35
    {
36 2
        $new = clone $this;
37 2
        $new->value = $value;
38 2
        return $new;
39
    }
40
}
41