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

JobMakeCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 7
loc 7
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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
class JobMakeCommand 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-job';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new job class for the specified module';
27
28
    protected $argumentName = 'name';
29
30
31
    /**
32
     * @return string
33
     */
34 2
    public function getDefaultNamespace()
35
    {
36 2
        return 'Jobs';
37
    }
38
39
40
    /**
41
     * Get the console command arguments.
42
     *
43
     * @return array
44
     */
45 60
    protected function getArguments()
46
    {
47
        return [
48 60
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
49
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
50
        ];
51
    }
52
53
54
    /**
55
     * Get template contents.
56
     *
57
     * @return string
58
     */
59 2
    protected function getTemplateContents()
60
    {
61 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
62
63 2
        return (new Stub('/job.stub', [
64 2
            'NAMESPACE' => $this->getClassNamespace($module),
65 2
            'CLASS'     => $this->getClass(),
66 2
        ]))->render();
67
    }
68
69
70
    /**
71
     * Get the destination file path.
72
     *
73
     * @return string
74
     */
75 2
    protected function getDestinationFilePath()
76
    {
77 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
78
79 2
        $jobPath = $this->laravel['modules']->config('paths.generator.jobs');
80
81 2
        return $path.$jobPath.'/'.$this->getFileName().'.php';
82
    }
83
84
85
    /**
86
     * @return string
87
     */
88 2
    private function getFileName()
89
    {
90 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...
91
    }
92
}
93