Passed
Push — master ( 9f7d35...3f1c7e )
by Wilmer
08:50 queued 06:32
created

SimpleConditionBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 23 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Query\Conditions;
6
7
use Yiisoft\Db\Expression\ExpressionBuilderInterface;
8
use Yiisoft\Db\Expression\ExpressionBuilderTrait;
9
use Yiisoft\Db\Expression\ExpressionInterface;
10
11
/**
12
 * Class NotConditionBuilder builds objects of {@see SimpleCondition}.
13
 */
14
class SimpleConditionBuilder implements ExpressionBuilderInterface
15
{
16
    use ExpressionBuilderTrait;
17
18
    /**
19
     * Method builds the raw SQL from the $expression that will not be additionally escaped or quoted.
20
     *
21
     * @param ExpressionInterface|SimpleCondition $expression the expression to be built.
22
     * @param array $params the binding parameters.
23
     *
24
     * @return string the raw SQL that will not be additionally escaped or quoted.
25
     */
26 105
    public function build(ExpressionInterface $expression, array &$params = []): string
27
    {
28 105
        $operator = $expression->getOperator();
0 ignored issues
show
Bug introduced by
The method getOperator() does not exist on Yiisoft\Db\Expression\ExpressionInterface. It seems like you code against a sub-type of Yiisoft\Db\Expression\ExpressionInterface such as Yiisoft\Db\Query\Conditions\ConjunctionCondition or Yiisoft\Db\Query\Conditions\BetweenCondition or Yiisoft\Db\Query\Conditions\SimpleCondition or Yiisoft\Db\Query\Conditions\ExistsCondition or Yiisoft\Db\Query\Conditions\InCondition or Yiisoft\Db\Query\Conditi...BetweenColumnsCondition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        /** @scrutinizer ignore-call */ 
29
        $operator = $expression->getOperator();
Loading history...
29 105
        $column = $expression->getColumn();
0 ignored issues
show
Bug introduced by
The method getColumn() does not exist on Yiisoft\Db\Expression\ExpressionInterface. It seems like you code against a sub-type of Yiisoft\Db\Expression\ExpressionInterface such as Yiisoft\Db\Query\Conditions\BetweenCondition or Yiisoft\Db\Query\Conditions\SimpleCondition or Yiisoft\Db\Query\Conditions\InCondition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $column = $expression->getColumn();
Loading history...
30 105
        $value = $expression->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on Yiisoft\Db\Expression\ExpressionInterface. It seems like you code against a sub-type of Yiisoft\Db\Expression\ExpressionInterface such as Yiisoft\Db\Pdo\PdoValue or Yiisoft\Db\Expression\ArrayExpression or Yiisoft\Db\Expression\JsonExpression or Yiisoft\Db\Query\Conditions\SimpleCondition or Yiisoft\Db\Query\Conditi...BetweenColumnsCondition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $value = $expression->getValue();
Loading history...
31
32 105
        if ($column instanceof ExpressionInterface) {
33 9
            $column = $this->queryBuilder->buildExpression($column, $params);
34 96
        } elseif (is_string($column) && strpos($column, '(') === false) {
35 96
            $column = $this->queryBuilder->getDb()->quoteColumnName($column);
36
        }
37
38 105
        if ($value === null) {
39
            return "$column $operator NULL";
40
        }
41
42 105
        if ($value instanceof ExpressionInterface) {
43 56
            return "$column $operator {$this->queryBuilder->buildExpression($value, $params)}";
44
        }
45
46 49
        $phName = $this->queryBuilder->bindParam($value, $params);
47
48 49
        return "$column $operator $phName";
49
    }
50
}
51