RegionsMigration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 1
A check() 0 7 2
A down() 0 4 1
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
}