Completed
Push — master ( 81f92d...d4d910 )
by Nicolas
06:52
created

GenerateJobCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 11.54 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 9
loc 78
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 7 1
A getTemplateContents() 9 9 1
A getDestinationFilePath() 0 8 1
A getFileName() 0 4 1
A getDefaultNamespace() 0 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 Nwidart\Modules\Support\Stub;
6
use Nwidart\Modules\Traits\ModuleCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class GenerateJobCommand extends GeneratorCommand
10
{
11
    use ModuleCommandTrait;
12
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'module:make-job';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Generate a new Job Class for the specified module';
26
27
    protected $argumentName = 'name';
28
29
    /**
30
     * Get the console command arguments.
31
     *
32
     * @return array
33
     */
34 34
    protected function getArguments()
35
    {
36
        return [
37 34
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
38 34
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
39 34
        ];
40
    }
41
42
    /**
43
     * Get template contents.
44
     *
45
     * @return string
46
     */
47 2 View Code Duplication
    protected function getTemplateContents()
1 ignored issue
show
Duplication introduced by
This method 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...
48
    {
49 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
50
51 2
        return (new Stub('/job.stub', [
52 2
            'NAMESPACE'         => $this->getClassNamespace($module),
53 2
            'CLASS'             => $this->getClass(),
54 2
        ]))->render();
55
    }
56
57
    /**
58
     * Get the destination file path.
59
     *
60
     * @return string
61
     */
62 2
    protected function getDestinationFilePath()
63
    {
64 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
65
66 2
        $jobPath = $this->laravel['modules']->config('paths.generator.jobs');
67
68 2
        return $path . $jobPath . '/' . $this->getFileName() . '.php';
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
     * @return string
81
     */
82 2
    public function getDefaultNamespace()
83
    {
84 2
        return 'Jobs';
85
    }
86
}
87