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

GenerateModelCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 22
dl 0
loc 90
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 3 1
A getDefaultNamespace() 0 3 1
A buildClass() 0 14 1
A getStub() 0 3 1
A handle() 0 13 3
1
<?php
2
3
namespace LaravelModulize\Console\Commands;
4
5
class GenerateModelCommand extends BaseGeneratorCommand
6
{
7
    /**
8
     * The name and signature of the console command.
9
     *
10
     * @var string
11
     */
12
    protected $signature = 'modulize:make:model {module} {name} {--c|controller} {--m|migration}';
13
14
    /**
15
     * The console command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Command to generate a Model inside a module';
20
21
    /**
22
     * Execute the console command.
23
     *
24
     * @return mixed
25
     */
26
    public function handle()
27
    {
28
        parent::handle();
29
30
        if ($this->option('controller')) {
31
            $this->call('modulize:make:controller', [
32
                'module' => $this->module,
33
                'name' => $this->getClassName($this->getNameInput()) . 'Controller',
34
                '--model' => $this->getNameInput(),
35
            ]);
36
        }
37
38
        if ($this->option('migration')) {
39
40
        }
41
    }
42
43
    /**
44
     * Get the stub file for the generator.
45
     *
46
     * @return string
47
     */
48
    protected function getStub(): string
49
    {
50
        return __DIR__ . '/stubs/Model.stub';
51
    }
52
53
    /**
54
     * Get the destination class path.
55
     *
56
     * @param  string  $name
57
     * @return string
58
     */
59
    protected function getPath($name): string
60
    {
61
        return $this->repository->modelPath($this->module) . '/' . $this->getNameInput() . '.php';
62
    }
63
64
    /**
65
     * Build the class with the given name.
66
     *
67
     * @param  string  $name
68
     * @return string
69
     */
70
    protected function buildClass($name)
71
    {
72
        $dummies = [
73
            'DummyClass',
74
            'DummyModuleNamespace',
75
            'DummyModelNamespace',
76
        ];
77
78
        $replacements = [
79
            $this->getClassName($this->getNameInput()),
80
            $this->repository->getModuleNamespace($this->module),
81
            $this->convertPathToNamespace($this->getNameInput()),
82
        ];
83
        return str_replace($dummies, $replacements, parent::buildClass($name));
84
    }
85
86
    /**
87
     * Get the default namespace for the class.
88
     *
89
     * @param  string  $rootNamespace
90
     * @return string
91
     */
92
    protected function getDefaultNamespace($rootNamespace)
93
    {
94
        return $this->repository->getModuleNamespace($this->module);
95
    }
96
}
97