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

NotCondition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

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