CompilesViews   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 46
rs 10
c 2
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compileRefreshMaterializedView() 0 3 1
A compileCreateView() 0 9 4
A compileDropView() 0 5 2
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
     * @param bool $materialized
15
     * @return string
16
     */
17
    public function compileCreateView($name, $query, $columns, $orReplace, bool $materialized = false)
18
    {
19
        $orReplaceSql = $orReplace ? 'or replace ' : '';
20
21
        $materializedSql = $materialized ? 'materialized ' : '';
22
23
        $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

23
        $columns = $columns ? '('.$this->/** @scrutinizer ignore-call */ columnize($columns).') ' : '';
Loading history...
24
25
        return 'create '.$orReplaceSql.$materializedSql.'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

25
        return 'create '.$orReplaceSql.$materializedSql.'view '.$this->/** @scrutinizer ignore-call */ wrapTable($name).' '.$columns.'as '.$query;
Loading history...
26
    }
27
28
    /**
29
     * Compile the query to drop a view.
30
     *
31
     * @param string $name
32
     * @param bool $ifExists
33
     * @return string
34
     */
35
    public function compileDropView($name, $ifExists)
36
    {
37
        $ifExists = $ifExists ? 'if exists ' : '';
38
39
        return 'drop view '.$ifExists.$this->wrapTable($name);
40
    }
41
42
    /**
43
     * Compile the query to refresh a materialized view.
44
     *
45
     * @param string $name
46
     * @return string
47
     */
48
    public function compileRefreshMaterializedView(string $name): string
49
    {
50
        return 'refresh materialized view ' . $this->wrapTable($name);
51
    }
52
}
53