MariaDbGrammar   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compileOrderByPath() 0 22 2
1
<?php
2
3
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars;
4
5
use Illuminate\Database\Query\Grammars\MariaDbGrammar as Base;
6
use Staudenmeir\LaravelAdjacencyList\Query\Grammars\Traits\CompilesMySqlAdjacencyLists;
7
8
class MariaDbGrammar extends Base implements ExpressionGrammar
9
{
10
    use CompilesMySqlAdjacencyLists;
11
12 5
    /**
13
     * Compile an "order by path" clause.
14 5
     *
15
     * @return string
16 5
     */
17 5
    public function compileOrderByPath()
18 5
    {
19
        $column = $this->model->getLocalKeyName();
20 5
21
        $path = $this->wrap(
22 5
            $this->model->getPathName()
23 1
        );
24
25
        $pathSeparator = $this->model->getPathSeparator();
26 4
27 4
        if (!$this->model->isIntegerAttribute($column)) {
28
            return "$path asc";
29 4
        }
30 4
31
        return <<<SQL
32
regexp_replace(
33 4
    regexp_replace(
34
        $path,
35
        '(^|[$pathSeparator])(\\\\d+)',
36 4
        '\\\\100000000000000000000\\\\2'
37
    ),
38
    '0+(\\\\d\{20\})([$pathSeparator]|$)',
39
    '\\\\1\\\\2'
40
) asc
41
SQL;
42
    }
43
}
44