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