Passed
Pull Request — 2.2 (#20357)
by Wilmer
13:33 queued 05:55
created

JsonExpressionBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 2
1
<?php
2
3
/**
4
 * @link https://www.yiiframework.com/
5
 * @copyright Copyright (c) 2008 Yii Software LLC
6
 * @license https://www.yiiframework.com/license/
7
 */
8
9
namespace yii\db\mysql;
10
11
use yii\db\ExpressionBuilderInterface;
12
use yii\db\ExpressionBuilderTrait;
13
use yii\db\ExpressionInterface;
14
use yii\db\JsonExpression;
15
use yii\db\Query;
16
use yii\helpers\Json;
17
18
/**
19
 * Class JsonExpressionBuilder builds [[JsonExpression]] for MySQL DBMS.
20
 *
21
 * @author Dmytro Naumenko <[email protected]>
22
 * @since 2.0.14
23
 */
24
class JsonExpressionBuilder implements ExpressionBuilderInterface
25
{
26
    use ExpressionBuilderTrait;
27
28
    const PARAM_PREFIX = ':qp';
29
30
31
    /**
32
     * {@inheritdoc}
33
     * @param JsonExpression|ExpressionInterface $expression the expression to be built
34
     */
35
    public function build(ExpressionInterface $expression, array &$params = [])
36
    {
37
        $value = $expression->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on yii\db\ExpressionInterface. It seems like you code against a sub-type of yii\db\ExpressionInterface such as yii\db\JsonExpression or yii\db\Query or yii\db\ArrayExpression or yii\db\PdoValue or yii\db\Expression or yii\db\conditions\BetweenColumnsCondition or yii\db\conditions\SimpleCondition. ( Ignorable by Annotation )

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

37
        /** @scrutinizer ignore-call */ 
38
        $value = $expression->getValue();
Loading history...
38
39
        if ($value instanceof Query) {
40
            list ($sql, $params) = $this->queryBuilder->build($value, $params);
41
            return "($sql)";
42
        }
43
44
        $placeholder = static::PARAM_PREFIX . count($params);
45
        $params[$placeholder] = Json::encode($value);
46
47
        return $placeholder;
48
    }
49
}
50