Passed
Pull Request — master (#36)
by Cristian
03:01 queued 42s
created

BackpackCrudControllerService::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 Webfactor\Laravel\Generators\Contracts\SchemaFieldAbstract;
6
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
7
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
8
use Webfactor\Laravel\Generators\Helper\ShortSyntaxArray;
9
use Webfactor\Laravel\Generators\Traits\CanGenerateFile;
10
11
class BackpackCrudControllerService extends ServiceAbstract implements ServiceInterface
12
{
13
    use CanGenerateFile;
14
15
    protected $key = 'crudController';
16
17
    public function getConsoleOutput()
18
    {
19
        return 'Generated controller: '.$this->command->naming[$this->key]->getRelativeFilePath();
20
    }
21
22
    protected function buildFileContent()
23
    {
24
        $this->replaceClassNamespace();
25
        $this->replaceClassName();
26
        $this->replaceModelRelatedStrings();
27
        $this->replaceRequestRelatedStrings();
28
        $this->replaceLanguageFileRelatedStrings();
29
        $this->replaceRouteFileRelatedStrings();
30
        $this->replaceFieldStrings();
31
        $this->replaceColumnStrings();
32
    }
33
34
    protected function replaceModelRelatedStrings()
35
    {
36
        $this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
        $this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
    }
39
40
    protected function replaceRequestRelatedStrings()
41
    {
42
        $this->fileContent = str_replace('__request_namespace__', $this->command->naming['crudRequest']->getNamespace(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
        $this->fileContent = str_replace('__request_class__', $this->command->naming['crudRequest']->getClassName(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
44
    }
45
46
    protected function replaceLanguageFileRelatedStrings()
47
    {
48
        $this->fileContent = str_replace('__languagefile_key__', $this->command->naming['languageFile']->getName(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
49
    }
50
51
    protected function replaceRouteFileRelatedStrings()
52
    {
53
        $this->fileContent = str_replace('__route_name__', $this->command->naming['routeFile']->getName(), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
54
    }
55
56
    protected function replaceFieldStrings()
57
    {
58
        $this->fileContent = str_replace('__fields__', ShortSyntaxArray::parse($this->command->schema->getCrudFields()->toArray()), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 152 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
    }
60
61
    protected function replaceColumnStrings()
62
    {
63
        $this->fileContent = str_replace('__columns__', ShortSyntaxArray::parse($this->command->schema->getCrudColumns()->toArray()), $this->fileContent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 154 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
64
    }
65
}
66