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

BackpackCrudModelService::getConsoleOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 2
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