JobMakeCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 79
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 4 1
A isJobSynchronous() 0 8 3
A stubOptions() 0 6 1
A stubName() 0 7 2
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Generator\Abstracts\AbstractGeneratorCommand;
6
use Foundation\Generator\Abstracts\ClassGeneratorCommand;
7
use Foundation\Generator\Events\JobGeneratedEvent;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class JobMakeCommand extends ClassGeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'larapi:make:job';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new job class for the specified module';
25
26
    /**
27
     * The name of the generated resource.
28
     *
29
     * @var string
30
     */
31
    protected $generatorName = 'job';
32
33
    /**
34
     * The file path.
35
     *
36
     * @var string
37
     */
38
    protected $filePath = '/Jobs';
39
40
    /**
41
     * The event that will fire when the file is created.
42
     *
43
     * @var string
44
     */
45
    protected $event = JobGeneratedEvent::class;
46
47 2
    protected function stubOptions(): array
48
    {
49
        return [
50 2
            'NAMESPACE' => $this->getClassNamespace(),
51 2
            'CLASS' => $this->getClassName(),
52 2
            'SYNC'  => $this->isJobSynchronous()
53
        ];
54
    }
55
56
    /**
57
     * Get the console command options.
58
     *
59
     * @return array
60
     */
61 26
    protected function setOptions() :array
62
    {
63
        return [
64 26
            ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'],
65
        ];
66
    }
67
68 2
    protected function isJobSynchronous(): bool
69
    {
70
        return once(function () {
71 2
            $option = $this->option('sync');
72 2
            if ($option !== null)
73 2
                $option = (bool)$option;
74
75 2
            return $option === null ? $this->confirm('Should the job run Synchronously?', false) : $option;
76 2
        });
77
    }
78
79
    /**
80
     * @return string
81
     */
82 2
    protected function stubName(): string
83
    {
84 2
        if ($this->isJobSynchronous()) {
85 1
            return 'job.stub';
86
        }
87
88 1
        return 'job-queued.stub';
89
    }
90
}
91