Passed
Pull Request — master (#343)
by Sergei
08:05 queued 05:38
created

SimpleCondition::getColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\QueryBuilder\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\QueryBuilder\Conditions\Interface\SimpleConditionInterface;
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
final 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
    /**
44
     * @throws InvalidArgumentException
45
     *
46
     * @psalm-suppress MixedArgument
47
     */
48
    public static function fromArrayDefinition(string $operator, array $operands): self
49
    {
50
        if (count($operands) !== 2) {
51
            throw new InvalidArgumentException("Operator '$operator' requires two operands.");
52
        }
53
54
        return new self($operands[0], $operator, $operands[1]);
55
    }
56
}
57