CompilesViews::compileRefreshMaterializedView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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