Completed
Push — master ( 0fd405...f8ea68 )
by Nicolas
8s
created

JobMakeCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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