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

ExistsCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArrayDefinition() 0 7 3
A getOperator() 0 3 1
A __construct() 0 2 1
A getQuery() 0 3 1
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