Passed
Push — master ( 9b6500...1e2780 )
by Jonas
08:34
created

MariaDbGrammar   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 29
ccs 11
cts 11
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
class MariaDbGrammar extends MySqlGrammar
6
{
7
    /**
8
     * Compile an "order by path" clause.
9
     *
10
     * @return string
11
     */
12 4
    public function compileOrderByPath()
13
    {
14 4
        $column = $this->model->getLocalKeyName();
15
16 4
        $path = $this->wrap(
17 4
            $this->model->getPathName()
18
        );
19
20 4
        $pathSeparator = $this->model->getPathSeparator();
21
22 4
        if (!$this->model->isIntegerAttribute($column)) {
23 1
            return "$path asc";
24
        }
25
26
        return <<<SQL
27 3
regexp_replace(
28
    regexp_replace(
29 3
        $path,
30 3
        '(^|[$pathSeparator])(\\\\d+)',
31
        '\\\\100000000000000000000\\\\2'
32
    ),
33 3
    '0+(\\\\d\{20\})([$pathSeparator]|$)',
34
    '\\\\1\\\\2'
35
) asc
36
SQL;
37
    }
38
}
39