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

Compare   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 5
c 2
b 1
f 0
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A withValue() 0 5 1
A getValue() 0 3 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