Passed
Push — Generators ( 1df58a...4d090d )
by Roy
04:17 queued 11s
created

GenerateControllerCommand::getDefaultNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LaravelModulize\Console\Commands;
4
5
use Illuminate\Support\Str;
6
7
class GenerateControllerCommand extends BaseGeneratorCommand
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'modulize:make:controller {module} {name} {--m|model=}';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Generate a controller for the module';
22
23
    /**
24
     * Execute the console command.
25
     *
26
     * @return mixed
27
     */
28
    public function handle()
29
    {
30
        parent::handle();
31
    }
32
33
    /**
34
     * Get the stub file for the generator.
35
     *
36
     * @return string
37
     */
38
    protected function getStub(): string
39
    {
40
        if ($this->option('model')) {
41
            return __DIR__ . '/stubs/ModelController.stub';
42
        }
43
44
        return __DIR__ . '/stubs/Controller.stub';
45
    }
46
47
    /**
48
     * Get the destination class path.
49
     *
50
     * @param  string  $name
51
     * @return string
52
     */
53
    protected function getPath($name): string
54
    {
55
        return $this->repository->controllerPath($this->module) . '/' . $this->getNameInput() . '.php';
56
    }
57
58
    /**
59
     * Build the class with the given name.
60
     *
61
     * @param  string  $name
62
     * @return string
63
     */
64
    protected function buildClass($name)
65
    {
66
        $dummies = [
67
            'DummyClass',
68
            'DummyModel',
69
            'DummyLowercasedModel',
70
            'DummyControllerNamespace',
71
            'DummyModuleNamespace',
72
        ];
73
74
        $replacements = [
75
            $this->getClassName($this->getNameInput()),
76
            str_replace('/', '\\', $this->option('model')),
77
            Str::lower($this->option('model')),
78
            $this->getClassNamespace($this->getNameInput()),
79
            $this->repository->getModuleNamespace($this->module),
80
        ];
81
82
        return str_replace($dummies, $replacements, parent::buildClass($name));
83
    }
84
85
    /**
86
     * Get the default namespace for the class.
87
     *
88
     * @param  string  $rootNamespace
89
     * @return string
90
     */
91
    protected function getDefaultNamespace($rootNamespace)
92
    {
93
        return $this->repository->getModuleNamespace($this->module);
94
    }
95
}
96