Passed
Push — master ( 2fd2da...07f956 )
by Arthur
35:40 queued 30:04
created

JobMakeCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Generator\Abstracts\AbstractGeneratorCommand;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class JobMakeCommand extends AbstractGeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'larapi:make:job';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new job class for the specified module';
23
24
    /**
25
     * The name of the generated resource.
26
     *
27
     * @var string
28
     */
29
    protected $generatorName = 'job';
30
31
    /**
32
     * The file path.
33
     *
34
     * @var string
35
     */
36
    protected $filePath = '/Jobs';
37
38 2
    protected function stubOptions(): array
39
    {
40
        return [
41 2
            'NAMESPACE' => $this->getClassNamespace(),
42 2
            'CLASS' => $this->getClassName(),
43
        ];
44
    }
45
46
    /**
47
     * Get the console command options.
48
     *
49
     * @return array
50
     */
51 102
    protected function getOptions()
52
    {
53
        return [
54 102
            ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'],
55
        ];
56
    }
57
58 2
    protected function isJobSynchronous(): bool
59
    {
60
        return once(function () {
61 2
            $option = $this->option('sync');
62 2
            if ($option !== null)
63 2
                $option = (bool)$option;
64
65 2
            return $option === null ? $this->confirm('Should the job run Synchronously?', false) : $option;
66 2
        });
67
    }
68
69
    /**
70
     * @return string
71
     */
72 2
    protected function stubName(): string
73
    {
74 2
        if ($this->isJobSynchronous()) {
75 1
            return 'job.stub';
76
        }
77
78 1
        return 'job-queued.stub';
79
    }
80
}
81