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

NotCondition::fromArrayDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
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\Expression\ExpressionInterface;
9
use Yiisoft\Db\QueryBuilder\Conditions\Interface\NotConditionInterface;
10
11
use function array_shift;
12
use function count;
13
14
/**
15
 * Condition that inverts passed {@see condition}.
16
 */
17
final class NotCondition implements NotConditionInterface
18
{
19
    public function __construct(private ExpressionInterface|array|null|string $condition)
20
    {
21
    }
22
23
    public function getCondition(): ExpressionInterface|array|null|string
24
    {
25
        return $this->condition;
26
    }
27
28
    /**
29
     * @throws InvalidArgumentException
30
     *
31
     * @psalm-suppress MixedArgument
32
     */
33
    public static function fromArrayDefinition(string $operator, array $operands): self
34
    {
35
        if (count($operands) !== 1) {
36
            throw new InvalidArgumentException("Operator '$operator' requires exactly one operand.");
37
        }
38
39
        return new self(array_shift($operands));
40
    }
41
}
42