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

NotificationMakeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultNamespace() 4 4 1
A getTemplateContents() 9 9 1
A getDestinationFilePath() 8 8 1
A getFileName() 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\Stub;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
9 View Code Duplication
final class NotificationMakeCommand 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...
10
{
11
12
    use ModuleCommandTrait;
13
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'module:make-notification';
20
21
    protected $argumentName = 'name';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Create a new notification class for the specified module.';
29
30
31
    /**
32
     * @return string
33
     */
34 2
    public function getDefaultNamespace()
35
    {
36 2
        return 'Notifications';
37
    }
38
39
40
    /**
41
     * Get template contents.
42
     *
43
     * @return string
44
     */
45 2
    protected function getTemplateContents()
46
    {
47 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
48
49 2
        return (new Stub('/notification.stub', [
50 2
            'NAMESPACE' => $this->getClassNamespace($module),
51 2
            'CLASS'     => $this->getClass(),
52 2
        ]))->render();
53
    }
54
55
56
    /**
57
     * Get the destination file path.
58
     *
59
     * @return string
60
     */
61 2
    protected function getDestinationFilePath()
62
    {
63 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
64
65 2
        $mailPath = $this->laravel['modules']->config('paths.generator.notifications', 'Notifications');
66
67 2
        return $path.$mailPath.'/'.$this->getFileName().'.php';
68
    }
69
70
71
    /**
72
     * @return string
73
     */
74 2
    private function getFileName()
75
    {
76 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...
77
    }
78
79
80
    /**
81
     * Get the console command arguments.
82
     *
83
     * @return array
84
     */
85 60
    protected function getArguments()
86
    {
87
        return [
88 60
            ['name', InputArgument::REQUIRED, 'The name of the notification class.'],
89
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
90
        ];
91
    }
92
}
93