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

SimpleCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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