CitiesMigration::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
3
4
namespace agoalofalife\database\migrations;
5
use agoalofalife\Contracts\Checker;
6
use agoalofalife\Contracts\ContractMigration;
7
use \Illuminate\Database\Capsule\Manager as Capsule;
8
9
class CitiesMigration implements ContractMigration, Checker
10
{
11
    public function execute()
12
    {
13
        Capsule::schema()->create('cities', function ($table) {
14
            $table->increments('id');
15
            $table->integer('region_id')->unsigned()->index()->nullable();
16
            $table->foreign('region_id')->references('id')->on('regions')->onDelete('cascade');
17
            $table->string('title', 100);
18
            $table->string('area', 100);
19
            $table->text('description')->nullable();
20
            $table->string('code')->nullable()->comments('unique value');
21
            $table->timestamps();
22
        });
23
    }
24
25
    public function check(callable $callback)
26
    {
27
        if ( Capsule::schema()->hasTable('cities') === false )
28
        {
29
            call_user_func($callback, $this);
30
        }
31
    }
32
33
    /**
34
     * Reverse the migrations.
35
     *
36
     * @return void
37
     */
38
    public function down()
39
    {
40
        Capsule::schema()->dropIfExists('cities');
41
    }
42
}