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

ExistsCondition::getQuery()   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 Yiisoft\Db\Exception\InvalidArgumentException;
8
use Yiisoft\Db\QueryBuilder\Conditions\Interface\ExistConditionInterface;
9
use Yiisoft\Db\Query\QueryInterface;
10
11
/**
12
 * Condition that represents `EXISTS` operator.
13
 */
14
final class ExistsCondition implements ExistConditionInterface
15
{
16
    public function __construct(private string $operator, private QueryInterface $query)
17
    {
18
    }
19
20
    public function getOperator(): string
21
    {
22
        return $this->operator;
23
    }
24
25
    public function getQuery(): QueryInterface
26
    {
27
        return $this->query;
28
    }
29
30
    /**
31
     * @throws InvalidArgumentException
32
     *
33
     * @psalm-suppress MixedArgument
34
     */
35
    public static function fromArrayDefinition(string $operator, array $operands): self
36
    {
37
        if (!isset($operands[0]) || !$operands[0] instanceof QueryInterface) {
38
            throw new InvalidArgumentException('Sub query for EXISTS operator must be a Query object.');
39
        }
40
41
        return new self($operator, $operands[0]);
42
    }
43
}
44