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

MailMakeCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 77
loc 77
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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