SqlServerBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 54
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getViewColumnListing() 0 8 1
A createView() 0 7 2
A dropView() 0 5 2
1
<?php
2
3
namespace Staudenmeir\LaravelMigrationViews\Schema\Builders;
4
5
use Illuminate\Database\Schema\SqlServerBuilder as Base;
6
7
class SqlServerBuilder extends Base
8
{
9
    use ManagesViews {
10
        createView as createViewParent;
11
    }
12
13
    /**
14
     * Create a new view on the schema.
15
     *
16
     * @param string $name
17
     * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|string $query
18
     * @param array|null $columns
19
     * @param bool $orReplace
20
     * @param bool $materialized
21
     * @return void
22
     */
23
    public function createView($name, $query, ?array $columns = null, $orReplace = false, bool $materialized = false)
0 ignored issues
show
Unused Code introduced by
The parameter $materialized 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

23
    public function createView($name, $query, ?array $columns = null, $orReplace = false, /** @scrutinizer ignore-unused */ bool $materialized = false)

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...
24
    {
25
        if ($orReplace) {
26
            $this->dropViewIfExists($name);
27
        }
28
29
        $this->createViewParent($name, $query, $columns);
30
    }
31
32
    /**
33
     * Drop a view from the schema.
34
     *
35
     * @param string $name
36
     * @param bool $ifExists
37
     * @return void
38
     */
39
    public function dropView($name, $ifExists = false)
40
    {
41
        $this->connection->statement(
42
            $this->grammar->compileDropView($name, $ifExists),
43
            $ifExists ? [$this->connection->getTablePrefix().$name] : []
44
        );
45
    }
46
47
    /**
48
     * Get the column listing for a given view.
49
     *
50
     * @param string $name
51
     * @return array
52
     */
53
    public function getViewColumnListing($name)
54
    {
55
        $results = $this->connection->selectFromWriteConnection(
56
            $this->grammar->compileViewColumnListing(),
57
            [$this->connection->getTablePrefix().$name]
58
        );
59
60
        return array_map(fn ($result) => ((object) $result)->name, $results);
61
    }
62
}
63