Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

JobMakeCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'larapi:make:job';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Create a new job class for the specified module';
24
25
    /**
26
     * The name of the generated resource.
27
     *
28
     * @var string
29
     */
30
    protected $generatorName = 'job';
31
32
    /**
33
     * The file path.
34
     *
35
     * @var string
36
     */
37
    protected $filePath = '/Jobs';
38
39
    protected function stubOptions(): array
40
    {
41
        return [
42
            'NAMESPACE' => $this->getClassNamespace(),
43
            'CLASS' => $this->getClassName(),
44
        ];
45
    }
46
47
    /**
48
     * Get the console command options.
49
     *
50
     * @return array
51
     */
52
    protected function getOptions()
53
    {
54
        return [
55
            ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'],
56
        ];
57
    }
58
59
    protected function isJobSynchronous(): bool
60
    {
61
        return once(function () {
62
            $option = $this->option('sync');
63
            return app()->runningInConsole() && !$option ? $this->confirm('Should the job run Synchronously?',false) : $option;
0 ignored issues
show
introduced by
The method runningInConsole() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
            return app()->/** @scrutinizer ignore-call */ runningInConsole() && !$option ? $this->confirm('Should the job run Synchronously?',false) : $option;
Loading history...
64
        });
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    protected function stubName(): string
71
    {
72
        if ($this->isJobSynchronous()) {
73
            return 'job.stub';
74
        }
75
        return 'job-queued.stub';
76
    }
77
}
78