Passed
Push — master ( c36ed8...8867a0 )
by Quentin
13:25 queued 05:48
created

AddLocaleColumnToTwillMediables   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 24
rs 10
wmc 7
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class AddLocaleColumnToTwillMediables extends Migration
7
{
8
    public function up()
9
    {
10
        if (Schema::hasTable('mediables') && !Schema::hasColumn('mediables', 'locale')) {
11
            Schema::table('mediables', function (Blueprint $table) {
12
                $table->string('locale', 7)->default($this->getCurrentLocale())->index();
13
            });
14
        }
15
    }
16
17
    public function down()
18
    {
19
        if (Schema::hasTable('mediables') && Schema::hasColumn('mediables', 'locale')) {
20
            Schema::table('mediables', function (Blueprint $table) {
21
                $table->dropIndex('mediables_locale_index');
22
                $table->dropColumn('locale');
23
            });
24
        }
25
    }
26
27
    function getCurrentLocale()
28
    {
29
        return getLocales()[0] ?? config('app.locale');
30
    }
31
}
32