Completed
Push — master ( d7820a...8cd137 )
by recca
04:27
created

SqliteModel::createSchema()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Repository;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Schema\Blueprint;
7
use Recca0120\Repository\SqliteConnectionResolver as ConnectionResolver;
8
9
abstract class SqliteModel extends Model
10
{
11
    /**
12
     * $tableCreated.
13
     *
14
     * @var array
15
     */
16
    protected static $tableCreated = [];
17
18
    /**
19
     * Get the table associated with the model.
20
     *
21
     * @return string
22
     */
23 31
    public function getTable()
24
    {
25 31
        return $this->createTable(parent::getTable());
26
    }
27
28
    /**
29
     * Resolve a connection instance.
30
     *
31
     * @param  string|null  $connection
32
     * @return \Illuminate\Database\Connection
33
     */
34 31
    public static function resolveConnection($connection = null)
35
    {
36 31
        return ConnectionResolver::getInstance()->connection($connection);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @param string $table
43
     * @return string
44
     */
45 31
    protected function createTable($table)
46
    {
47 31
        if (isset(static::$tableCreated[$table]) === true) {
48 31
            return $table;
49
        }
50
51 2
        $schema = $this->getConnection()->getSchemaBuilder();
52 2
        if ($schema->hasTable($table) === false) {
53 2
            $schema->create($table, function (Blueprint $table) {
54 2
                $this->createSchema($table);
55 2
            });
56 2
            static::$tableCreated[$table] = true;
57 2
            if (method_exists($this, 'handleTableCreated') === true) {
58 1
                $this->handleTableCreated($table);
0 ignored issues
show
Bug introduced by
The method handleTableCreated() does not exist on Recca0120\Repository\SqliteModel. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
59
            }
60
        }
61
62 2
        return $table;
63
    }
64
65
    /**
66
     * createSchema.
67
     *
68
     * @param  Blueprint $table
69
     * @return void
70
     */
71
    abstract protected function createSchema(Blueprint $table);
72
}
73