Completed
Push — master ( 5649ba...c37d73 )
by recca
03:09
created

Sqlite   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A schema() 0 4 1
A resolveConnection() 0 4 1
createSchema() 0 1 ?
A fireModelEvent() 0 15 3
1
<?php
2
3
namespace Recca0120\Repository;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Schema\Blueprint;
7
8
abstract class Sqlite extends Model
9
{
10
    /**
11
     * Get a schema builder instance.
12
     *
13
     * @return \Illuminate\Database\Schema\Builder
14
     */
15
    public function schema()
16
    {
17
        return $this->getConnection()->getSchemaBuilder();
18
    }
19
20
    /**
21
     * Resolve a connection instance.
22
     *
23
     * @param  string|null  $connection
24
     * @return \Illuminate\Database\Connection
25
     */
26
    public static function resolveConnection($connection = null)
27
    {
28
        return SqliteConnectionResolver::getInstance()->connection($connection);
29
    }
30
31
    /**
32
     * createSchema.
33
     *
34
     * @param  Blueprint $table
35
     * @return void
36
     */
37
    abstract protected function createSchema(Blueprint $table);
38
39
    /**
40
     * Fire the given event for the model.
41
     *
42
     * @param  string  $event
43
     * @param  bool  $halt
44
     * @return mixed
45
     */
46
    protected function fireModelEvent($event, $halt = true)
47
    {
48
        if ($event === 'booting') {
49
            $table = $this->getTable();
50
            $schema = $this->schema();
51
52
            if ($schema->hasTable($table) === false) {
53
                $schema->create($table, function (Blueprint $table) {
54
                    $this->createSchema($table);
55
                });
56
            }
57
        }
58
59
        return parent::fireModelEvent($event, $halt);
60
    }
61
}
62