Passed
Push — master ( 1f27ac...52075a )
by Alexander
04:53 queued 02:24
created

Between::toCriteriaArray()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Filter;
6
7
use DateTimeInterface;
8
use Yiisoft\Data\Reader\FilterAssert;
9
use Yiisoft\Data\Reader\FilterInterface;
10
11
/**
12
 * `Between` filter defines a criteria so the value of the field with a given name
13
 * is between the minimal value and the maximal value.
14
 */
15
final class Between implements FilterInterface
16
{
17
    private bool|DateTimeInterface|float|int|string $minValue;
18
19
    private bool|DateTimeInterface|float|int|string $maxValue;
20
21
    /**
22
     * @param string $field Name of the field to compare.
23
     * @param bool|DateTimeInterface|float|int|string $minValue Minimal field value.
24
     * @param bool|DateTimeInterface|float|int|string $maxValue Maximal field value.
25
     */
26 16
    public function __construct(private string $field, mixed $minValue, mixed $maxValue)
27
    {
28 16
        FilterAssert::isScalarOrInstanceOfDateTimeInterface($minValue);
29 12
        FilterAssert::isScalarOrInstanceOfDateTimeInterface($maxValue);
30
31 8
        $this->minValue = $minValue;
32 8
        $this->maxValue = $maxValue;
33
    }
34
35 8
    public function toCriteriaArray(): array
36
    {
37 8
        return [self::getOperator(), $this->field, $this->minValue, $this->maxValue];
38
    }
39
40 112
    public static function getOperator(): string
41
    {
42 112
        return 'between';
43
    }
44
}
45