Completed
Push — master ( 8e707c...9307a2 )
by Maarten
01:15
created

CreateMigrationAction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 1
1
<?php
2
3
namespace Mtolhuys\LaravelSchematics\Actions;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Facades\File;
7
use Mtolhuys\LaravelSchematics\Services\RuleParser;
8
9
class CreateMigrationAction
10
{
11
    /**
12
     * @param $request
13
     * @return string
14
     */
15
    public function execute($request)
16
    {
17
        $model = ucfirst($request['name']);
18
        $table = Str::plural(Str::snake($model));
19
        $stub = __DIR__ . '/../../resources/stubs/migration.stub';
20
        $filename = 'database/migrations/' . date('Y_m_d_His') . "_create_{$table}_table.php";
21
        $columns = RuleParser::rulesToMigrationColumns($request['fields']);
22
23
        File::put(base_path($filename), str_replace(
24
            ['$classname$', '$table$', '$columns$'],
25
            ['Create' . Str::plural($model) . 'Table', $table, $columns],
26
            File::get($stub)
27
        ));
28
    }
29
}
30