RenameColumn   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\FieldGenerator\Listeners;
4
5
use Illuminate\Support\Facades\Schema;
6
use Hechoenlaravel\JarvisFoundation\FieldGenerator\Events\FieldWasEdited;
7
8
class RenameColumn
9
{
10
    /**
11
     * Once the field has been edited in the DB Record
12
     * The column in the entity table will be edited.
13
     * @param FieldWasCreated $event
14
     */
15
    public function handle(FieldWasEdited $event)
16
    {
17
        $field = $event->field;
18
        $rename = $event->rename;
19
        $oldSlug = $event->oldSlug;
20
        Schema::table($event->field->entity->getTableName(), function ($table) use ($field, $rename, $oldSlug) {
21
            if ($rename) {
22
                $table->renameColumn($oldSlug, $field->slug);
23
            }
24
        });
25
        Schema::table($event->field->entity->getTableName(), function ($table) use ($field) {
26
            $table->{$field->getType()->getColumnType()}($field->slug)->nullable()->default($field->default)->change();
27
        });
28
    }
29
}
30