Completed
Pull Request — master (#354)
by Martin
02:25
created

EventMakeCommand::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 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Nwidart\Modules\Support\Stub;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class EventMakeCommand extends GeneratorCommand
10
{
11
12
    use ModuleCommandTrait;
13
14
    protected $argumentName = 'name';
15
16
    /**
17
     * The console command name.
18
     *
19
     * @var string
20
     */
21
    protected $name = 'module:make-event';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Create a new event class for the specified module';
29
30
31 2
    public function getTemplateContents()
32
    {
33 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
34
35 2
        return (new Stub('/event.stub', [
36 2
            'NAMESPACE' => $this->getClassNamespace($module)."\\".config('modules.paths.generator.event'),
37 2
            "CLASS"     => $this->getClass(),
38 2
        ]))->render();
39
    }
40
41
42 2
    public function getDestinationFilePath()
43
    {
44 2
        $path       = $this->laravel['modules']->getModulePath($this->getModuleName());
45 2
        $seederPath = $this->laravel['modules']->config('paths.generator.event');
46
47 2
        return $path.$seederPath.'/'.$this->getFileName().'.php';
48
    }
49
50
51
    /**
52
     * @return string
53
     */
54 2
    protected function getFileName()
55
    {
56 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...
57
    }
58
59
60
    /**
61
     * Get the console command arguments.
62
     *
63
     * @return array
64
     */
65 60
    protected function getArguments()
66
    {
67
        return [
68 60
            ['name', InputArgument::REQUIRED, 'The name of the event.'],
69
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
70
        ];
71
    }
72
}
73