Completed
Pull Request — master (#2)
by Lanre
05:41
created

GenerateEventCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 77
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 8 1
A getOptions() 0 6 1
A getTemplateContents() 0 10 1
A getDestinationFilePath() 0 9 1
A getFileName() 0 4 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Nwidart\Modules\Commands\GeneratorCommand;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Pingpong\Support\Stub;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class GenerateEventCommand extends GeneratorCommand
12
{
13
    use ModuleCommandTrait;
14
15
    protected $argumentName = 'name';
16
17
    /**
18
     * The console command name.
19
     *
20
     * @var string
21
     */
22
    protected $name = 'module:make-event';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Generate a new Event Class for the specified module';
30
31
    /**
32
     * Get the console command arguments.
33
     *
34
     * @return array
35
     */
36 25
    protected function getArguments()
37
    {
38
        return [
39 25
            ['name', InputArgument::REQUIRED, 'The name of the command.'],
40 25
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
41 25
        ];
42
43
    }
44
45
    /**
46
     * Get the console command options.
47
     *
48
     * @return array
49
     */
50 25
    protected function getOptions()
51
    {
52
        return [
53 25
            ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
54 25
        ];
55
    }
56
57 2
    public function getTemplateContents()
58
    {
59 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
60
61 2
        return (new Stub('/event.stub', [
62 2
            'NAMESPACE' => $this->getClassNamespace($module) . "\\" . config("modules.paths.generator.event"),
63 2
            "CLASS" => $this->getClass(),
64 2
            'DUMMYNAMESPACE' => $this->laravel->getNamespace() . "Events"
65 2
        ]))->render();
66
    }
67
68 2
    public function getDestinationFilePath()
69
    {
70 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
71
72 2
        $seederPath = $this->laravel['modules']->config('paths.generator.event');
73
74 2
        return $path . $seederPath . '/' . $this->getFileName() . '.php';
75
76
    }
77
78
    /**
79
     * @return string
80
     */
81 2
    protected function getFileName()
82
    {
83 2
        return studly_case($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, studly_case() 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...
84
    }
85
86
87
}
88