Completed
Push — master ( 39fb48...a4bc13 )
by Nicolas
02:36
created

JobMakeCommand::getStubName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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
use Symfony\Component\Console\Input\InputOption;
9
10
class JobMakeCommand extends GeneratorCommand
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
     * @return string
32
     */
33 3
    public function getDefaultNamespace()
34
    {
35 3
        return 'Jobs';
36
    }
37
38
    /**
39
     * Get the console command arguments.
40
     *
41
     * @return array
42
     */
43 69 View Code Duplication
    protected function getArguments()
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...
44
    {
45
        return [
46 69
            ['name', InputArgument::REQUIRED, 'The name of the job.'],
47
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
48
        ];
49
    }
50
51
    /**
52
     * Get the console command options.
53
     *
54
     * @return array
55
     */
56 69
    protected function getOptions()
57
    {
58
        return [
59 69
            ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'],
60
        ];
61
    }
62
63
    /**
64
     * Get template contents.
65
     *
66
     * @return string
67
     */
68 3
    protected function getTemplateContents()
69
    {
70 3
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
71
72 3
        return (new Stub($this->getStubName(), [
73 3
            'NAMESPACE' => $this->getClassNamespace($module),
74 3
            'CLASS'     => $this->getClass(),
75 3
        ]))->render();
76
    }
77
78
    /**
79
     * Get the destination file path.
80
     *
81
     * @return string
82
     */
83 3
    protected function getDestinationFilePath()
84
    {
85 3
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
86
87 3
        $jobPath = $this->laravel['modules']->config('paths.generator.jobs');
88
89 3
        return $path . $jobPath . '/' . $this->getFileName() . '.php';
90
    }
91
92
    /**
93
     * @return string
94
     */
95 3
    private function getFileName()
96
    {
97 3
        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...
98
    }
99
100
    /**
101
     * @return string
102
     */
103 3
    protected function getStubName(): string
104
    {
105 3
        if ($this->option('sync')) {
106 1
            return '/job.stub';
107
        }
108
109 2
        return '/job-queued.stub';
110
    }
111
}
112