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

SqlServerGrammar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 36
ccs 7
cts 7
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compileViewColumnListing() 0 3 1
A compileDropView() 0 5 2
A compileViewExists() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelMigrationViews\Schema\Grammars;
4
5
use Illuminate\Database\Schema\Grammars\SqlServerGrammar as Base;
6
7
class SqlServerGrammar extends Base
8
{
9
    use CompilesViews;
10
11
    /**
12
     * Compile the query to drop a view.
13
     *
14
     * @param string $name
15
     * @param bool $ifExists
16
     * @return string
17
     */
18 11
    public function compileDropView($name, $ifExists)
19
    {
20 11
        $ifExists = $ifExists ? 'if exists ('.$this->compileViewExists().') ' : '';
21
22 11
        return $ifExists.'drop view '.$this->wrapTable($name);
23
    }
24
25
    /**
26
     * Compile the query to determine if a view exists.
27
     *
28
     * @return string
29
     */
30 11
    public function compileViewExists()
31
    {
32 11
        return "select * from sys.objects where type = 'V' and name = ?";
33
    }
34
35
    /**
36
     * Compile the query to determine the column listing of a view.
37
     *
38
     * @return string
39
     */
40 1
    public function compileViewColumnListing()
41
    {
42 1
        return "select columns.name from sys.columns as columns
43
                join sys.objects as objects on objects.object_id = columns.object_id
44
                where objects.type = 'V' and objects.name = ?";
45
    }
46
}
47