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

EventMakeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 65
loc 65
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplateContents() 9 9 1
A getDestinationFilePath() 8 8 1
A getFileName() 4 4 1
A getDefaultNamespace() 4 4 1
A getArguments() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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