Completed
Pull Request — master (#666)
by reallyli
02:28
created

EventMakeCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 7
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Nwidart\Modules\Support\Config\GenerateConfigReader;
6
use Nwidart\Modules\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 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...
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
    public function getTemplateContents()
31
    {
32
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
33
34
        return (new Stub('/event.stub', [
35
            'NAMESPACE' => $this->getClassNamespace($module),
36
            'CLASS' => $this->getClass(),
37
        ]))->render();
38
    }
39
40
    public function getDestinationFilePath()
41
    {
42
        $path       = $this->laravel['modules']->getModulePath($this->getModuleName());
43
44
        $eventPath = GenerateConfigReader::read('event');
45
46
        return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php';
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    protected function getFileName()
53
    {
54
        return studly_case($this->argument('name'));
55
    }
56
57
    public function getDefaultNamespace() : string
58
    {
59
        return $this->laravel['modules']->config('paths.generator.event.path', 'Events');
60
    }
61
62
    /**
63
     * Get the console command arguments.
64
     *
65
     * @return array
66
     */
67
    protected function getArguments()
68
    {
69
        return [
70
            ['name', InputArgument::REQUIRED, 'The name of the event.'],
71
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
72
        ];
73
    }
74
}
75