Passed
Push — master ( c65027...a39d50 )
by Wilmer
18:53 queued 16:02
created

NotConditionBuilder::getNegationOperator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\QueryBuilder\Condition\Builder;
6
7
use Yiisoft\Db\Exception\Exception;
8
use Yiisoft\Db\Exception\InvalidArgumentException;
9
use Yiisoft\Db\Exception\InvalidConfigException;
10
use Yiisoft\Db\Exception\NotSupportedException;
11
use Yiisoft\Db\Expression\ExpressionBuilderInterface;
12
use Yiisoft\Db\QueryBuilder\Condition\Interface\NotConditionInterface;
13
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
14
15
/**
16
 * Class NotConditionBuilder builds objects of {@see NotCondition}.
17
 */
18
class NotConditionBuilder implements ExpressionBuilderInterface
19
{
20
    public function __construct(private QueryBuilderInterface $queryBuilder)
21
    {
22
    }
23
24
    /**
25
     * @throws Exception|InvalidArgumentException|InvalidConfigException|NotSupportedException
26
     */
27
    public function build(NotConditionInterface $expression, array &$params = []): string
28
    {
29
        $operand = $expression->getCondition();
30
31
        if ($operand === '') {
32
            return '';
33
        }
34
35
        $expression = $this->queryBuilder->buildCondition($operand, $params);
36
37
        return "{$this->getNegationOperator()} ($expression)";
38
    }
39
40
    protected function getNegationOperator(): string
41
    {
42
        return 'NOT';
43
    }
44
}
45