Completed
Pull Request — 4.0 (#124)
by
unknown
02:12
created

OracleBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 96
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A create() 0 14 1
A table() 0 10 1
A createBlueprint() 0 7 1
A drop() 0 5 1
A dropIfExists() 0 5 1
1
<?php
2
3
namespace Yajra\Oci8\Schema;
4
5
use Closure;
6
use Illuminate\Database\Connection;
7
use Illuminate\Database\Schema\Builder;
8
9
class OracleBuilder extends Builder
10
{
11
    /**
12
     * @var \Yajra\Oci8\Schema\OracleAutoIncrementHelper
13
     */
14
    public $helper;
15
16
    /**
17
     * @param Connection $connection
18
     */
19
    public function __construct(Connection $connection)
20
    {
21
        $this->connection = $connection;
22
        $this->grammar    = $connection->getSchemaGrammar();
23
        $this->helper     = new OracleAutoIncrementHelper($connection);
24
        $this->comment    = new Comment($connection);
0 ignored issues
show
Bug introduced by
The property comment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * Create a new table on the schema.
29
     *
30
     * @param  string $table
31
     * @param  Closure $callback
32
     * @return \Illuminate\Database\Schema\Blueprint
33
     */
34
    public function create($table, Closure $callback)
35
    {
36
        $blueprint = $this->createBlueprint($table);
37
38
        $blueprint->create();
39
40
        $callback($blueprint);
41
42
        $this->build($blueprint);
43
44
        $this->comment->setComments($blueprint);
45
46
        $this->helper->createAutoIncrementObjects($blueprint, $table);
47
    }
48
49
    /**
50
     * Changes an existing table on the schema.
51
     *
52
     * @param  string $table
53
     * @param  Closure $callback
54
     * @return \Illuminate\Database\Schema\Blueprint
55
     */
56
    public function table($table, Closure $callback)
57
    {
58
        $blueprint = $this->createBlueprint($table);
59
60
        $callback($blueprint);
61
62
        $this->build($blueprint);
63
64
        $this->comment->setComments($blueprint);
65
    }
66
67
    /**
68
     * Create a new command set with a Closure.
69
     *
70
     * @param  string $table
71
     * @param  Closure $callback
72
     * @return \Illuminate\Database\Schema\Blueprint
73
     */
74
    protected function createBlueprint($table, Closure $callback = null)
75
    {
76
        $blueprint = new OracleBlueprint($table, $callback);
77
        $blueprint->setTablePrefix($this->connection->getTablePrefix());
78
79
        return $blueprint;
80
    }
81
82
    /**
83
     * Drop a table from the schema.
84
     *
85
     * @param  string $table
86
     * @return \Illuminate\Database\Schema\Blueprint
87
     */
88
    public function drop($table)
89
    {
90
        $this->helper->dropAutoIncrementObjects($table);
91
        parent::drop($table);
92
    }
93
94
    /**
95
     * Indicate that the table should be dropped if it exists.
96
     *
97
     * @return \Illuminate\Support\Fluent
98
     */
99
    public function dropIfExists($table)
100
    {
101
        $this->helper->dropAutoIncrementObjects($table);
102
        parent::dropIfExists($table);
103
    }
104
}
105