Passed
Push — master ( 00bef5...064b0e )
by Jonas
02:59
created

CompilesMySqlExpressions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compileInsertUsing() 0 5 1
A compileCycle() 0 9 2
1
<?php
2
3
namespace Staudenmeir\LaravelCte\Query\Grammars\Traits;
4
5
use Illuminate\Database\Query\Builder;
6
7
trait CompilesMySqlExpressions
8
{
9
    use CompilesExpressions;
10
11
    /**
12
     * Compile the cycle detection.
13
     *
14
     * @param \Illuminate\Database\Query\Builder $query
15
     * @param array $expression
16
     * @return string
17
     */
18 40
    public function compileCycle(Builder $query, array $expression)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

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

18
    public function compileCycle(/** @scrutinizer ignore-unused */ Builder $query, array $expression)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20 40
        if (!$expression['cycle']) {
21 38
            return '';
22
        }
23
24 2
        $columns = $this->columnize($expression['cycle']['columns']);
0 ignored issues
show
Bug introduced by
It seems like columnize() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        /** @scrutinizer ignore-call */ 
25
        $columns = $this->columnize($expression['cycle']['columns']);
Loading history...
25
26 2
        return " cycle $columns restrict";
27
    }
28
29
    /**
30
     * Compile an insert statement using a subquery into SQL.
31
     *
32
     * @param \Illuminate\Database\Query\Builder $query
33
     * @param array $columns
34
     * @param string $sql
35
     * @return string
36
     */
37 4
    public function compileInsertUsing(Builder $query, array $columns, string $sql)
38
    {
39 4
        $insert = "insert into {$this->wrapTable($query->from)} ({$this->columnize($columns)}) ";
0 ignored issues
show
Bug introduced by
It seems like wrapTable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

39
        $insert = "insert into {$this->/** @scrutinizer ignore-call */ wrapTable($query->from)} ({$this->columnize($columns)}) ";
Loading history...
40
41 4
        return $insert.$this->compileExpressions($query, $query->expressions).' '.$sql;
0 ignored issues
show
Bug introduced by
The property expressions does not seem to exist on Illuminate\Database\Query\Builder.
Loading history...
42
    }
43
}
44