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

InCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 52
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\Query\Conditions\Interface\InConditionInterface;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_INTERFACE, expecting T_STRING or '{' on line 9 at column 32
Loading history...
10
use Yiisoft\Db\Query\QueryInterface;
11
12
/**
13
 * Class InCondition represents `IN` condition.
14
 */
15
class InCondition implements InConditionInterface
16
{
17
    public function __construct(
18
        private array|string|Iterator $column,
19
        private string $operator,
20
        private int|iterable|Iterator|QueryInterface $values
21
    ) {
22
    }
23
24
    public function getColumn(): array|string|Iterator
25
    {
26
        return $this->column;
27
    }
28
29
    public function getOperator(): string
30
    {
31
        return $this->operator;
32
    }
33
34
    public function getValues(): int|iterable|Iterator|QueryInterface
35
    {
36
        return $this->values;
37
    }
38
39
    public static function fromArrayDefinition(string $operator, array $operands): self
40
    {
41
        if (!isset($operands[0], $operands[1])) {
42
            throw new InvalidArgumentException("Operator '$operator' requires two operands.");
43
        }
44
45
        return new static($operands[0], $operator, $operands[1]);
46
    }
47
}
48