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

NotConditionBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 11 2
A __construct() 0 2 1
A getNegationOperator() 0 3 1
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