Passed
Pull Request — master (#36)
by Cristian
02:10
created

BackpackCrudModelService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 3
dl 0
loc 29
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConsoleOutput() 0 4 1
A buildFileContent() 0 7 1
A replaceFillable() 0 9 1
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Services;
4
5
use Illuminate\Contracts\Filesystem\FileNotFoundException;
6
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
7
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
8
use Webfactor\Laravel\Generators\Traits\CanGenerateFile;
9
10
class BackpackCrudModelService extends ServiceAbstract implements ServiceInterface
11
{
12
    use CanGenerateFile;
13
14
    protected $key = 'crudModel';
15
16
    public function getConsoleOutput()
17
    {
18
        return 'Generated model: '.$this->command->naming[$this->key]->getRelativeFilePath();
19
    }
20
21
    protected function buildFileContent()
22
    {
23
        $this->replaceClassNamespace();
24
        $this->replaceClassName();
25
        $this->replaceTableName();
26
        $this->replaceFillable();
27
    }
28
29
    protected function replaceFillable()
30
    {
31
        $fillables = $this->command->schema->getStructure()
32
            ->map(function ($item) {
33
                return "'" . $item->name . "'";
34
            });
35
36
        $this->fileContent = str_replace('__fillable__', $fillables->implode(', '), $this->fileContent);
37
    }
38
}
39