Passed
Branch psalm-3 (d5d890)
by Wilmer
02:56
created

BetweenCondition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Query\Conditions;
6
7
use Yiisoft\Db\Exception\InvalidArgumentException;
8
use Yiisoft\Db\Query\Conditions\Interface\BetweenConditionInterface;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_INTERFACE, expecting T_STRING or '{' on line 8 at column 32
Loading history...
9
use Yiisoft\Db\Expression\Expression;
10
11
/**
12
 * Class BetweenCondition represents a `BETWEEN` condition.
13
 */
14
class BetweenCondition implements BetweenConditionInterface
15
{
16
    public function __construct(
17
        private string|Expression $column,
18
        private string $operator,
19
        private mixed $intervalStart,
20
        private mixed $intervalEnd
21
    ) {
22
    }
23
24
    public function getColumn(): string|Expression
25
    {
26
        return $this->column;
27
    }
28
29
    public function getIntervalEnd(): mixed
30
    {
31
        return $this->intervalEnd;
32
    }
33
34
    public function getIntervalStart(): mixed
35
    {
36
        return $this->intervalStart;
37
    }
38
39
    public function getOperator(): string
40
    {
41
        return $this->operator;
42
    }
43
44
    public static function fromArrayDefinition(string $operator, array $operands): self
45
    {
46
        if (!isset($operands[0], $operands[1], $operands[2])) {
47
            throw new InvalidArgumentException("Operator '$operator' requires three operands.");
48
        }
49
50
        return new static($operands[0], $operator, $operands[1], $operands[2]);
51
    }
52
}
53