Passed
Push — master ( 429883...c19044 )
by Dallas
13:38 queued 05:53
created

Builder::getForeignKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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 1
    use Macroable;
14
15
    public $name;
16
17 1
    public function createView(string $view, string $select, $materialize = false): void
18
    {
19 1
        $blueprint = $this->createBlueprint($view);
20 1
        $blueprint->createView($view, $select, $materialize);
21 1
        $this->build($blueprint);
22 1
    }
23
24 1
    public function dropView(string $view): void
25
    {
26 1
        $blueprint = $this->createBlueprint($view);
27 1
        $blueprint->dropView($view);
28 1
        $this->build($blueprint);
29 1
    }
30
31 2
    public function hasView(string $view): bool
32
    {
33 2
        return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [
34 2
            $this->connection->getConfig()['schema'],
35 2
            $this->connection->getTablePrefix() . $view,
36 2
        ])) > 0;
37
    }
38
39 1
    public function getForeignKeys(string $tableName): array
40
    {
41 1
        return $this->connection->selectFromWriteConnection(
42 1
            $this->grammar->compileForeignKeysListing($tableName)
43
        );
44
    }
45
46 2
    public function getViewDefinition($view): string
47
    {
48 2
        $results = $this->connection->selectFromWriteConnection($this->grammar->compileViewDefinition(), [
49 2
            $this->connection->getConfig()['schema'],
50 2
            $this->connection->getTablePrefix() . $view,
51
        ]);
52 2
        return count($results) > 0 ? $results[0]->view_definition : '';
53
    }
54
55
    /**
56
     * @param string $table
57
     * @return Blueprint|\Illuminate\Database\Schema\Blueprint
58
     */
59 34
    protected function createBlueprint($table, Closure $callback = null)
60
    {
61 34
        return new Blueprint($table, $callback);
62
    }
63
}
64