Passed
Pull Request — master (#36)
by Cristian
01:57
created

BackpackCrudModelService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
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 28
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConsoleOutput() 0 3 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
        return 'Generated model: '.$this->command->naming[$this->key]->getRelativeFilePath();
18
    }
19
20
    protected function buildFileContent()
21
    {
22
        $this->replaceClassNamespace();
23
        $this->replaceClassName();
24
        $this->replaceTableName();
25
        $this->replaceFillable();
26
    }
27
28
    protected function replaceFillable()
29
    {
30
        $fillables = $this->command->schema->getStructure()
31
            ->map(function ($item) {
32
                return "'" . $item->name . "'";
33
            });
34
35
        $this->fileContent = str_replace('__fillable__', $fillables->implode(', '), $this->fileContent);
36
    }
37
}
38