Test Failed
Push — main ( 894963...0f30b5 )
by Rafael
05:41
created

Migration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
dl 0
loc 28
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createTable() 0 7 1
A getLastBatch() 0 9 2
1
<?php
2
3
namespace CoreModules\Admin\Model;
4
5
use Alxarafe\Base\Model\Model;
6
use Illuminate\Database\Capsule\Manager as Capsule;
7
use Illuminate\Database\Schema\Blueprint;
8
9
/**
10
 * The "migrations" table contains the list of updates to the database tables.
11
 */
12
class Migration extends Model
13
{
14
    protected $table = 'migrations';
15
    protected $fillable = ['migration', 'batch'];
16
17
    public static function getLastBatch()
18
    {
19
        $instance = new static;
20
21
        if (!Capsule::schema()->hasTable($instance->getTable())) {
22
            static::createTable();
23
        }
24
25
        return static::max('batch') ?? 0;
26
    }
27
28
    /**
29
     * Create the migration table if it does not exist.
30
     *
31
     * @return void
32
     */
33
    private static function createTable()
34
    {
35
        Capsule::schema()->create('migrations', function (Blueprint $table) {
36
            $table->id();
37
            $table->string('migration');
38
            $table->integer('batch')->unsigned();
39
            $table->timestamps();
40
        });
41
    }
42
43
}
44