CreateTableInDatabase   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\EntityGenerator\Listeners;
4
5
use Illuminate\Support\Facades\Schema;
6
use Hechoenlaravel\JarvisFoundation\EntityGenerator\Events\EntityWasCreated;
7
use Hechoenlaravel\JarvisFoundation\EntityGenerator\Events\TableWasCreatedInDb;
8
9
/**
10
 * Class CreateTableInDatabase
11
 * @package Hechoenlaravel\JarvisFoundation\EntityGenerator\Listeners
12
 */
13
class CreateTableInDatabase
14
{
15
    /**
16
     * Handle the event.
17
     * If the entity is supposed to create a
18
     * table in the Database, it will do
19
     * It won't do anything otherwise
20
     * @param  Events  $event
21
     * @return void
22
     */
23
    public function handle(EntityWasCreated $event)
24
    {
25
        if ((bool) $event->entity->create_table) {
26
            Schema::create($event->entity->table_name, function ($table) {
27
                $table->increments('id');
28
                $table->timestamps();
29
                $table->softDeletes();
30
            });
31
            event(new TableWasCreatedInDb($event->entity));
32
        }
33
    }
34
}
35