Passed
Push — master ( 3415eb...56b5c5 )
by Jonas
04:04
created

CompilesViews::compileCreateView()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Staudenmeir\LaravelMigrationViews\Schema\Grammars;
4
5
trait CompilesViews
6
{
7
    /**
8
     * Compile the query to create a view.
9
     *
10
     * @param string $name
11
     * @param string $query
12
     * @param array|null $columns
13
     * @param bool $orReplace
14
     * @return string
15
     */
16 40
    public function compileCreateView($name, $query, $columns, $orReplace)
17
    {
18 40
        $orReplace = $orReplace ? 'or replace ' : '';
19
20 40
        $columns = $columns ? '('.$this->columnize($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

20
        $columns = $columns ? '('.$this->/** @scrutinizer ignore-call */ columnize($columns).') ' : '';
Loading history...
21
22 40
        return 'create '.$orReplace.'view '.$this->wrapTable($name).' '.$columns.'as '.$query;
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

22
        return 'create '.$orReplace.'view '.$this->/** @scrutinizer ignore-call */ wrapTable($name).' '.$columns.'as '.$query;
Loading history...
23
    }
24
25
    /**
26
     * Compile the query to drop a view.
27
     *
28
     * @param string $name
29
     * @param bool $ifExists
30
     * @return string
31
     */
32 33
    public function compileDropView($name, $ifExists)
33
    {
34 33
        $ifExists = $ifExists ? 'if exists ' : '';
35
36 33
        return 'drop view '.$ifExists.$this->wrapTable($name);
37
    }
38
39
    /**
40
     * Compile the query to determine if a view exists.
41
     *
42
     * @return string
43
     */
44 6
    public function compileViewExists()
45
    {
46 6
        return 'select * from information_schema.views where table_schema = ? and table_name = ?';
47
    }
48
}
49