Passed
Pull Request — master (#282)
by Wilmer
13:20
created

SimpleCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 49
ccs 14
cts 15
cp 0.9333
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\ExpressionInterface;
10
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 10 at column 32
Loading history...
11
12
use function count;
13
14
/**
15
 * Class SimpleCondition represents a simple condition like `"column" operator value`.
16
 */
17
class SimpleCondition implements SimpleConditionInterface
18
{
19
    public function __construct(
20 251
        private string|array|ExpressionInterface $column,
21
        private string $operator,
22 251
        private array|int|string|Iterator|ExpressionInterface|null $value
23 251
    ) {
24 251
    }
25 251
26
    public function getColumn(): string|array|ExpressionInterface
27
    {
28
        return $this->column;
29
    }
30 291
31
    public function getOperator(): string
32 291
    {
33
        return $this->operator;
34
    }
35
36
    public function getValue(): array|int|string|Iterator|ExpressionInterface|null
37
    {
38 291
        return $this->value;
39
    }
40 291
41
    public static function fromArrayDefinition(string $operator, array $operands): self
42
    {
43
        if (count($operands) !== 2) {
44
            throw new InvalidArgumentException("Operator '$operator' requires two operands.");
45
        }
46 291
47
        return new static($operands[0], $operator, $operands[1]);
48 291
    }
49
}
50