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

ExistsCondition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
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 Yiisoft\Db\Exception\InvalidArgumentException;
8
use Yiisoft\Db\Query\Conditions\Interface\ExistConditionInterface;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_INTERFACE, expecting T_STRING or '{' on line 8 at column 32
Loading history...
9
use Yiisoft\Db\Query\QueryInterface;
10
11
/**
12
 * Condition that represents `EXISTS` operator.
13
 */
14
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
    public static function fromArrayDefinition(string $operator, array $operands): self
31
    {
32
        if (!isset($operands[0]) || !$operands[0] instanceof QueryInterface) {
33
            throw new InvalidArgumentException('Sub query for EXISTS operator must be a Query object.');
34
        }
35
36
        return new static($operator, $operands[0]);
37
    }
38
}
39