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

GenerateEventCommand::getFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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