Builder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
dl 0
loc 64
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createView() 0 5 1
A getViewDefinition() 0 7 2
A hasView() 0 6 1
A createBlueprint() 0 3 1
A dropView() 0 5 1
A getForeignKeys() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Schema;
6
7
use Closure;
8
use Illuminate\Database\Schema\PostgresBuilder as BasePostgresBuilder;
9
use Illuminate\Support\Traits\Macroable;
10
11
class Builder extends BasePostgresBuilder
12
{
13
    use Macroable;
14
15
    public $name;
16
17
    /**
18
     * @codeCoverageIgnore
19
     */
20
    public function createView(string $view, string $select, $materialize = false): void
21
    {
22
        $blueprint = $this->createBlueprint($view);
23
        $blueprint->createView($view, $select, $materialize);
24
        $this->build($blueprint);
25
    }
26
27
    /**
28
     * @codeCoverageIgnore
29
     */
30
    public function dropView(string $view): void
31
    {
32
        $blueprint = $this->createBlueprint($view);
33
        $blueprint->dropView($view);
34
        $this->build($blueprint);
35
    }
36
37
    /**
38
     * @codeCoverageIgnore
39
     */
40
    public function hasView($view): bool
41
    {
42
        return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [
43
            $this->connection->getConfig()['schema'],
44
            $this->connection->getTablePrefix() . $view,
45
        ])) > 0;
46
    }
47
48
    /**
49
     * @codeCoverageIgnore
50
     */
51
    public function getForeignKeys($tableName): array
52
    {
53
        return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName));
54
    }
55
56
    /**
57
     * @codeCoverageIgnore
58
     */
59
    public function getViewDefinition($view): string
60
    {
61
        $results = $this->connection->selectFromWriteConnection($this->grammar->compileViewDefinition(), [
62
            $this->connection->getConfig()['schema'],
63
            $this->connection->getTablePrefix() . $view,
64
        ]);
65
        return count($results) > 0 ? $results[0]->view_definition : '';
66
    }
67
68
    /**
69
     * @param string $table
70
     * @return Blueprint|\Illuminate\Database\Schema\Blueprint
71
     */
72 27
    protected function createBlueprint($table, Closure $callback = null)
73
    {
74 27
        return new Blueprint($this->connection, $table, $callback);
0 ignored issues
show
Bug introduced by
$table of type string is incompatible with the type Closure expected by parameter $callback of Umbrellio\Postgres\Schema\Blueprint::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return new Blueprint($this->connection, /** @scrutinizer ignore-type */ $table, $callback);
Loading history...
75
    }
76
}
77