Passed
Push — master ( 3cb518...ba9ea6 )
by Thomas
40s
created

BackpackCrudModelService::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Services;
4
5
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
6
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
7
8
class BackpackCrudModelService extends ServiceAbstract implements ServiceInterface
9
{
10
    protected $relativeToBasePath = 'app/Models';
11
12
    private $fillable;
13
14
    public function call()
15
    {
16
        $this->command->call('make:crud-model', [
17
            'name' => $this->getName($this->command->entity),
18
        ]);
19
20
        $this->addLatestFileToIdeStack();
21
        $this->fillFillableAttributeInGeneratedModelFromSchema();
22
    }
23
24
    /**
25
     * @param string $entity
26
     *
27
     * @return string
28
     */
29
    public function getName(string $entity): string
30
    {
31
        return ucfirst($entity);
32
    }
33
34 View Code Duplication
    private function fillFillableAttributeInGeneratedModelFromSchema()
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...
35
    {
36
        $modelFile = end($this->command->filesToBeOpened);
37
38
        $model = $this->filesystem->get($modelFile);
39
        $model = str_replace('__fillable__', $this->getFillableFromSchema(), $model);
40
        $this->filesystem->put($modelFile, $model);
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    private function getFillableFromSchema()
47
    {
48
        $this->command->schema->getStructure()->each(function ($field) {
49
            $this->fillable .= "'" . $field->getName() . "',\n";
50
        });
51
52
        return $this->fillable;
53
    }
54
}
55