Completed
Push — master ( 15e02a...758c52 )
by Nicolas
05:13
created

CommandCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 102
ccs 24
cts 24
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 7 1
A getOptions() 0 6 1
A getTemplateContents() 0 10 1
A getDestinationFilePath() 0 8 1
A getFileName() 0 4 1
A getCommandName() 0 4 2
A getDefaultNamespace() 0 4 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Support\Str;
6
use Pingpong\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class CommandCommand extends GeneratorCommand
12
{
13
    use ModuleCommandTrait;
14
15
    /**
16
     * The name of argument name.
17
     *
18
     * @var string
19
     */
20
    protected $argumentName = 'name';
21
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'module:make-command';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Generate new Artisan command for the specified module.';
35
36
    /**
37
     * Get the console command arguments.
38
     *
39
     * @return array
40
     */
41 16
    protected function getArguments()
42
    {
43
        return array(
44 16
            array('name', InputArgument::REQUIRED, 'The name of the command.'),
45 16
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
46 16
        );
47
    }
48
49
    /**
50
     * Get the console command options.
51
     *
52
     * @return array
53
     */
54 16
    protected function getOptions()
55
    {
56
        return array(
57 16
            array('command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null),
58 16
        );
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64 3
    protected function getTemplateContents()
65
    {
66 3
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
67
68 3
        return (new Stub('/command.stub', [
69 3
            'COMMAND_NAME' => $this->getCommandName(),
70 3
            'NAMESPACE' => $this->getClassNamespace($module),
71 3
            'CLASS' => $this->getClass(),
72 3
        ]))->render();
73
    }
74
75
    /**
76
     * @return mixed
77
     */
78 3
    protected function getDestinationFilePath()
79
    {
80 3
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
81
82 3
        $seederPath = $this->laravel['modules']->config('paths.generator.command');
83
84 3
        return $path.$seederPath.'/'.$this->getFileName().'.php';
85
    }
86
87
    /**
88
     * @return string
89
     */
90 3
    private function getFileName()
91
    {
92 3
        return Str::studly($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
93
    }
94
95
    /**
96
     * @return string
97
     */
98 3
    private function getCommandName()
99
    {
100 3
        return $this->option('command') ?: 'command:name';
101
    }
102
103
    /**
104
     * Get default namespace.
105
     *
106
     * @return string
107
     */
108 3
    public function getDefaultNamespace()
109
    {
110 3
        return 'Console';
111
    }
112
}
113