Passed
Push — master ( af341e...2b2ec9 )
by Jonas
07:18 queued 05:16
created

MySqlGrammar::compileJsonValueSelect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Staudenmeir\EloquentJsonRelations\Grammars;
4
5
use Illuminate\Database\Query\Grammars\MySqlGrammar as Base;
6
7
class MySqlGrammar extends Base implements JsonGrammar
8
{
9
    /**
10
     * Compile a "JSON array" statement into SQL.
11
     *
12
     * @param string $column
13
     * @return string
14
     */
15 25
    public function compileJsonArray($column)
16
    {
17 25
        return 'json_array('.$this->wrap($column).')';
18
    }
19
20
    /**
21
     * Compile a "JSON object" statement into SQL.
22
     *
23
     * @param string $column
24
     * @param int $levels
25
     * @return string
26
     */
27 22
    public function compileJsonObject($column, $levels)
28
    {
29 22
        return str_repeat('json_object(?, ', $levels)
30 22
                .$this->wrap($column)
31 22
                .str_repeat(')', $levels);
32
    }
33
34
    /**
35
     * Compile a "JSON value select" statement into SQL.
36
     *
37
     * @param string $column
38
     * @return string
39
     */
40 11
    public function compileJsonValueSelect(string $column): string
41
    {
42 11
        return $this->wrap($column);
43
    }
44
}
45