Issues (18)

src/Builder/JsonExpressionBuilder.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite\Builder;
6
7
use JsonException;
8
use Yiisoft\Db\Exception\Exception;
9
use Yiisoft\Db\Exception\InvalidArgumentException;
10
use Yiisoft\Db\Exception\InvalidConfigException;
11
use Yiisoft\Db\Exception\NotSupportedException;
12
use Yiisoft\Db\Expression\ExpressionBuilderInterface;
13
use Yiisoft\Db\Expression\ExpressionInterface;
14
use Yiisoft\Db\Expression\JsonExpression;
15
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
16
use Yiisoft\Db\Query\QueryInterface;
17
use Yiisoft\Json\Json;
18
19
/**
20
 * Builds expressions for {@see `Yiisoft\Db\Expression\JsonExpression`} for SQLite.
21
 */
22
final class JsonExpressionBuilder implements ExpressionBuilderInterface
23
{
24 13
    public function __construct(private QueryBuilderInterface $queryBuilder)
25
    {
26 13
    }
27
28
    /**
29
     * The method builds the raw SQL from the `$expression` that won't be additionally escaped or quoted.
30
     *
31
     * @param JsonExpression $expression The expression to build.
32
     * @param array $params The binding parameters.
33
     *
34
     * @throws Exception
35
     * @throws InvalidArgumentException
36
     * @throws InvalidConfigException
37
     * @throws JsonException
38
     * @throws NotSupportedException
39
     *
40
     * @return string The raw SQL that won't be additionally escaped or quoted.
41
     */
42 13
    public function build(ExpressionInterface $expression, array &$params = []): string
43
    {
44 13
        $value = $expression->getValue();
0 ignored issues
show
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\Expression\ArrayExpression or Yiisoft\Db\Expression\JsonExpression or Yiisoft\Db\Command\Param or Yiisoft\Db\QueryBuilder\...lumnsConditionInterface or Yiisoft\Db\QueryBuilder\...impleConditionInterface or Yiisoft\Db\QueryBuilder\...\LikeConditionInterface. ( Ignorable by Annotation )

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

44
        /** @scrutinizer ignore-call */ 
45
        $value = $expression->getValue();
Loading history...
45
46 13
        if ($value instanceof QueryInterface) {
47 2
            [$sql, $params] = $this->queryBuilder->build($value, $params);
48
49 2
            return "($sql)";
50
        }
51
52 11
        return $this->queryBuilder->bindParam(Json::encode($value), $params);
53
    }
54
}
55