FirebirdGrammar   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 20
c 1
b 0
f 0
dl 0
loc 73
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A selectPathList() 0 5 1
A compileInitialPath() 0 3 1
A compileRecursivePath() 0 7 2
A getRecursivePathBindings() 0 3 1
A getCycleDetectionBindings() 0 3 1
A compileCycleDetection() 0 6 1
A compileCycleDetectionRecursiveSelect() 0 3 1
A compilePivotColumnNullValue() 0 3 1
A compileCycleDetectionInitialSelect() 0 3 1
A supportsUnionInRecursiveExpression() 0 3 1
A compileCycleDetectionStopConstraint() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars;
4
5
use HarryGulliford\Firebird\Query\Grammars\FirebirdGrammar as Base;
0 ignored issues
show
Bug introduced by
The type HarryGulliford\Firebird\...rammars\FirebirdGrammar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Database\Query\Builder;
7
use RuntimeException;
8
9
class FirebirdGrammar extends Base implements ExpressionGrammar
10
{
11
    use OrdersByPath;
12
13
    public function compileInitialPath($column, $alias)
14
    {
15
        return 'cast(' . $this->wrap($column) . ' as varchar(8191)) as ' . $this->wrap($alias);
16
    }
17
18
    public function compileRecursivePath($column, $alias, bool $reverse = false)
19
    {
20
        $wrappedColumn = $this->wrap($column);
21
        $wrappedAlias = $this->wrap($alias);
22
        $placeholder = 'cast(? as varchar(8191))';
23
24
        return $reverse ? "($wrappedColumn || $placeholder || $wrappedAlias)" : "($wrappedAlias || $placeholder || $wrappedColumn)";
25
    }
26
27
    public function getRecursivePathBindings($separator)
28
    {
29
        return [$separator];
30
    }
31
32
    public function selectPathList(Builder $query, $expression, $column, $pathSeparator, $listSeparator)
33
    {
34
        return $query->selectRaw(
35
            'list(' . $this->wrap($column) . ", '$listSeparator')"
36
        )->from($expression);
37
    }
38
39
    /**
40
     * Compile a pivot column null value.
41
     *
42
     * @param string $typeName
43
     * @param string $type
44
     * @return string
45
     */
46
    public function compilePivotColumnNullValue(string $typeName, string $type): string
47
    {
48
        throw new RuntimeException('This graph relationship feature is not supported on Firebird.'); // @codeCoverageIgnore
49
    }
50
51
    public function compileCycleDetection(string $localKey, string $path): string
52
    {
53
        $localKey = $this->wrap($localKey);
54
        $path = $this->wrap($path);
55
56
        return "position($localKey || ?, $path) > 0 or position(? || $localKey || ?, $path) > 0";
57
    }
58
59
    public function getCycleDetectionBindings(string $pathSeparator): array
60
    {
61
        return [$pathSeparator, $pathSeparator, $pathSeparator];
62
    }
63
64
    public function compileCycleDetectionInitialSelect(string $column): string
65
    {
66
        return 'false as ' . $this->wrap($column);
67
    }
68
69
    public function compileCycleDetectionRecursiveSelect(string $sql, string $column): string
70
    {
71
        return $sql;
72
    }
73
74
    public function compileCycleDetectionStopConstraint(string $column): string
75
    {
76
        return 'not ' . $this->wrap($column);
77
    }
78
79
    public function supportsUnionInRecursiveExpression(): bool
80
    {
81
        return false;
82
    }
83
}
84