Completed
Push — master ( 4fafa1...e65f27 )
by Nicolas
12:12
created

EventMakeCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 7
loc 7
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 Illuminate\Support\Str;
6
use Nwidart\Modules\Support\Config\GenerateConfigReader;
7
use Nwidart\Modules\Support\Stub;
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11 View Code Duplication
class EventMakeCommand extends GeneratorCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 = 'Create a new event class for the specified module';
30
31 4
    public function getTemplateContents()
32
    {
33 4
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
34
35 4
        return (new Stub('/event.stub', [
36 4
            'NAMESPACE' => $this->getClassNamespace($module),
37 4
            'CLASS' => $this->getClass(),
38 4
        ]))->render();
39
    }
40
41 4
    public function getDestinationFilePath()
42
    {
43 4
        $path       = $this->laravel['modules']->getModulePath($this->getModuleName());
44
45 4
        $eventPath = GenerateConfigReader::read('event');
46
47 4
        return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php';
48
    }
49
50
    /**
51
     * @return string
52
     */
53 4
    protected function getFileName()
54
    {
55 4
        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 or null; 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...
56
    }
57
58 4
    public function getDefaultNamespace() : string
59
    {
60 4
        $module = $this->laravel['modules'];
61
62 4
        return $module->config('paths.generator.event.namespace') ?: $module->config('paths.generator.event.path', 'Events');
63
    }
64
65
    /**
66
     * Get the console command arguments.
67
     *
68
     * @return array
69
     */
70 120
    protected function getArguments()
71
    {
72
        return [
73 120
            ['name', InputArgument::REQUIRED, 'The name of the event.'],
74
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
75
        ];
76
    }
77
}
78