CreateModelAction::getFillables()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Mtolhuys\LaravelSchematics\Actions\Model;
4
5
use Mtolhuys\LaravelSchematics\Services\StubWriter;
6
7
class CreateModelAction
8
{
9
    /**
10
     * @param $request
11
     * @return void
12
     */
13
    public function execute($request)
14
    {
15
        $name = $request['name'];
16
        $stub = __DIR__ . '/../../../resources/stubs/model.stub';
17
        $file = config('schematics.model.path') . "/{$name}.php";
18
19
        (new StubWriter($file, $stub))->write([
20
            '$fillables$' => $this->getFillables($request['fields']),
21
            '$namespace$' => rtrim(config('schematics.model.namespace'), '\\'),
22
            '$model$' => $name,
23
        ]);
24
    }
25
26
    /**
27
     * @param array $fields
28
     * @return string
29
     */
30 View Code Duplication
    private function getFillables(array $fields): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $fillables = '';
33
34
        foreach ($fields as $index => $field) {
35
            if ($index === 0) {
36
                $fillables .= "'{$field['name']}',";
37
            } else {
38
                $fillables .= PHP_EOL . str_repeat(' ', 8) . "'{$field['name']}',";
39
            }
40
        }
41
42
        return $fillables;
43
    }
44
}
45