Completed
Push — master ( c37d73...04c6f6 )
by recca
01:30
created

Sqlite   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 4 1
A resolveConnection() 0 4 1
A createTable() 0 16 3
createSchema() 0 1 ?
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
     * $tableCreated.
12
     *
13
     * @var array
14
     */
15
    protected static $tableCreated = [];
16
17
    /**
18
     * Get the table associated with the model.
19
     *
20
     * @return string
21
     */
22 30
    public function getTable()
23
    {
24 30
        return $this->createTable(parent::getTable());
25
    }
26
27
    /**
28
     * Resolve a connection instance.
29
     *
30
     * @param  string|null  $connection
31
     * @return \Illuminate\Database\Connection
32
     */
33 30
    public static function resolveConnection($connection = null)
34
    {
35 30
        return SqliteConnectionResolver::getInstance()->connection($connection);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @param string $table
42
     * @return string
43
     */
44 30
    protected function createTable($table)
45
    {
46 30
        if (isset(static::$tableCreated[$table]) === true) {
47 30
            return $table;
48
        }
49
50 1
        $schema = $this->getConnection()->getSchemaBuilder();
51 1
        if ($schema->hasTable($table) === false) {
52 1
            $schema->create($table, function (Blueprint $table) {
53 1
                $this->createSchema($table);
54 1
            });
55 1
            static::$tableCreated[$table] = true;
56
        }
57
58 1
        return $table;
59
    }
60
61
    /**
62
     * createSchema.
63
     *
64
     * @param  Blueprint $table
65
     * @return void
66
     */
67
    abstract protected function createSchema(Blueprint $table);
68
}
69