JobMakeCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultNamespace() 0 6 2
A getTemplateContents() 0 9 1
A getDestinationFilePath() 0 7 1
A getStubName() 0 7 2
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Generators;
4
5
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader;
6
use Rawilk\LaravelModules\Support\Stub;
7
use Rawilk\LaravelModules\Traits\ModuleCommands;
8
9
class JobMakeCommand extends GeneratorCommand
10
{
11
    use ModuleCommands;
12
13
    /** @var string */
14
    protected $argumentName = 'name';
15
16
    /** @var string */
17
    protected $signature = 'module:make-job
18
                            {name : The name of the job}
19
                            {module? : The name of the module to create the job for}
20
                            {--sync : Indicates the job should be synchronous}';
21
22
    /** @var string */
23
    protected $description = 'Create a new job class for the specified module.';
24
25
    protected function getDefaultNamespace(): string
26
    {
27
        /** @var \Rawilk\LaravelModules\Contracts\Repository $module */
28
        $module = $this->laravel['modules'];
29
30
        return $module->config('paths.generator.jobs.namespace') ?: $module->config('paths.generator.jobs.path', 'Jobs');
31
    }
32
33
    protected function getDestinationFilePath(): string
34
    {
35
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
36
37
        $jobPath = GenerateConfigReader::read('jobs');
38
39
        return $path . $jobPath->getPath() . '/' . $this->getFileName() . '.php';
40
    }
41
42
    protected function getTemplateContents(): string
43
    {
44
        /** @var \Rawilk\LaravelModules\Module $module */
45
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
46
47
        return (new Stub($this->getStubName(), [
48
            'NAMESPACE' => $this->getClassNamespace($module),
49
            'CLASS'     => $this->getClass(),
50
        ]))->render();
51
    }
52
53
    private function getStubName(): string
54
    {
55
        if ($this->option('sync')) {
56
            return '/job.stub';
57
        }
58
59
        return '/job-queued.stub';
60
    }
61
}
62