CreateColumnInDatabase   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 18
rs 10

1 Method

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