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

InCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperator() 0 3 1
A getValues() 0 3 1
A __construct() 0 5 1
A getColumn() 0 3 1
A fromArrayDefinition() 0 7 2
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\QueryBuilder\Conditions\Interface\InConditionInterface;
10
use Yiisoft\Db\Query\QueryInterface;
11
12
/**
13
 * Class InCondition represents `IN` condition.
14
 */
15
final 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
    /**
40
     * @throws InvalidArgumentException
41
     *
42
     * @psalm-suppress MixedArgument
43
     */
44
    public static function fromArrayDefinition(string $operator, array $operands): self
45
    {
46
        if (!isset($operands[0], $operands[1])) {
47
            throw new InvalidArgumentException("Operator '$operator' requires two operands.");
48
        }
49
50
        return new self($operands[0], $operator, $operands[1]);
51
    }
52
}
53