RegionsMigration::check()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace agoalofalife\database\migrations;
3
use agoalofalife\Contracts\Checker;
4
use agoalofalife\Contracts\ContractMigration;
5
use \Illuminate\Database\Capsule\Manager as Capsule;
6
7
class RegionsMigration implements ContractMigration, Checker
8
{
9
    public function execute()
10
    {
11
        Capsule::schema()->create('regions', function ($table) {
12
            $table->increments('id');
13
            $table->integer('country_id')->unsigned()->index();
14
            $table->foreign('country_id')->references('id')->on('country')->onDelete('cascade');
15
            $table->string('title', 100);
16
            $table->text('description')->nullable();
17
            $table->timestamps();
18
        });
19
    }
20
21
    public function check(callable $callback)
22
    {
23
        if ( Capsule::schema()->hasTable('regions') === false )
24
        {
25
            call_user_func($callback, $this);
26
        }
27
    }
28
29
    /**
30
     * Reverse the migrations.
31
     *
32
     * @return void
33
     */
34
    public function down()
35
    {
36
        Capsule::schema()->dropIfExists('regions');
37
    }
38
}