1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Console; |
6
|
|
|
|
7
|
|
|
use Illuminate\Foundation\Console\ModelMakeCommand as IlluminateModelMakeCommand; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Concerns\ArangoCommands; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
|
12
|
|
|
class ModelMakeCommand extends IlluminateModelMakeCommand |
13
|
|
|
{ |
14
|
|
|
use ArangoCommands; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name = 'make:model'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Execute the console command. |
25
|
|
|
* |
26
|
|
|
* @return void|false |
27
|
|
|
*/ |
28
|
7 |
|
public function handle() |
29
|
|
|
{ |
30
|
|
|
/** @phpstan-ignore-next-line */ |
31
|
7 |
|
if ($this->hasOption('arangodb') && $this->option('arangodb')) { |
32
|
|
|
$this->useArangoDB = true; |
33
|
|
|
} |
34
|
|
|
|
35
|
7 |
|
if ($this->useFallback()) { |
36
|
|
|
/** @phpstan-ignore-next-line */ |
37
|
|
|
return parent::handle(); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** @phpstan-ignore-next-line */ |
41
|
7 |
|
if (parent::handle() === false && ! $this->option('force')) { |
|
|
|
|
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
7 |
|
$this->handleAllOption(); |
46
|
|
|
|
47
|
|
|
|
48
|
7 |
|
$this->handleOptions(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create a migration file for the model. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
2 |
|
protected function createMigration() |
58
|
|
|
{ |
59
|
2 |
|
if ($this->useFallback()) { |
60
|
|
|
parent::createMigration(); |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
$table = Str::snake(Str::pluralStudly(class_basename($this->argument('name')))); |
|
|
|
|
65
|
|
|
|
66
|
2 |
|
if ($this->option('pivot')) { |
67
|
|
|
$table = Str::singular($table); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
$createCommand = '--create'; |
71
|
2 |
|
if ($this->option('edge-pivot') || $this->option('edge-morph-pivot')) { |
72
|
1 |
|
$createCommand = '--edge'; |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
$this->call('make:migration', [ |
76
|
2 |
|
'name' => "create_{$table}_table", |
77
|
2 |
|
$createCommand => $table, |
78
|
2 |
|
'--fullpath' => true, |
79
|
2 |
|
]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
7 |
|
public function handleAllOption(): void |
86
|
|
|
{ |
87
|
7 |
|
if ($this->option('all')) { |
88
|
|
|
$this->input->setOption('factory', true); |
89
|
|
|
$this->input->setOption('seed', true); |
90
|
|
|
$this->input->setOption('migration', true); |
91
|
|
|
$this->input->setOption('controller', true); |
92
|
|
|
$this->input->setOption('policy', true); |
93
|
|
|
$this->input->setOption('resource', true); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
7 |
|
public function handleOptions(): void |
101
|
|
|
{ |
102
|
7 |
|
if ($this->option('factory')) { |
103
|
|
|
$this->createFactory(); |
104
|
|
|
} |
105
|
|
|
|
106
|
7 |
|
if ($this->option('migration')) { |
107
|
2 |
|
$this->createMigration(); |
108
|
|
|
} |
109
|
|
|
|
110
|
7 |
|
if ($this->option('seed')) { |
111
|
|
|
$this->createSeeder(); |
112
|
|
|
} |
113
|
|
|
|
114
|
7 |
|
if ($this->option('controller') || $this->option('resource') || $this->option('api')) { |
115
|
|
|
$this->createController(); |
116
|
|
|
} |
117
|
|
|
|
118
|
7 |
|
if ($this->option('policy')) { |
119
|
|
|
$this->createPolicy(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return array<array-key, string|null|int> |
|
|
|
|
125
|
|
|
*/ |
126
|
498 |
|
protected function getOptions() |
127
|
|
|
{ |
128
|
498 |
|
$options = parent::getOptions(); |
129
|
498 |
|
$options[] = [ |
130
|
498 |
|
'edge-pivot', |
131
|
498 |
|
null, |
132
|
498 |
|
InputOption::VALUE_NONE, 'The generated model uses a custom intermediate edge-collection model for ArangoDB', |
133
|
498 |
|
]; |
134
|
498 |
|
$options[] = [ |
135
|
498 |
|
'edge-morph-pivot', |
136
|
498 |
|
null, |
137
|
498 |
|
InputOption::VALUE_NONE, |
138
|
498 |
|
'The generated model uses a custom polymorphic intermediate edge-collection model for ArangoDB', |
139
|
498 |
|
]; |
140
|
|
|
|
141
|
498 |
|
if (!$this->arangodbIsDefaultConnection()) { |
142
|
|
|
$options[] = [ |
143
|
|
|
'arangodb', |
144
|
|
|
null, |
145
|
|
|
InputOption::VALUE_NONE, |
146
|
|
|
'Use ArangoDB instead of the default connection.', |
147
|
|
|
]; |
148
|
|
|
} |
149
|
|
|
|
150
|
498 |
|
return $options; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get the stub file for the generator. |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
7 |
|
protected function getStub() |
160
|
|
|
{ |
161
|
7 |
|
if ($this->useFallback()) { |
162
|
|
|
return parent::getStub(); |
163
|
|
|
} |
164
|
7 |
|
if ($this->option('pivot')) { |
165
|
1 |
|
return $this->resolveStubPath('/stubs/model.pivot.stub'); |
166
|
|
|
} |
167
|
|
|
|
168
|
6 |
|
if ($this->option('morph-pivot')) { |
169
|
1 |
|
return $this->resolveStubPath('/stubs/model.morph-pivot.stub'); |
170
|
|
|
} |
171
|
|
|
|
172
|
5 |
|
if ($this->option('edge-pivot')) { |
173
|
2 |
|
return $this->resolveStubPath('/stubs/model.edge-pivot.stub'); |
174
|
|
|
} |
175
|
|
|
|
176
|
3 |
|
if ($this->option('edge-morph-pivot')) { |
177
|
1 |
|
return $this->resolveStubPath('/stubs/model.edge-morph-pivot.stub'); |
178
|
|
|
} |
179
|
|
|
|
180
|
2 |
|
return $this->resolveStubPath('/stubs/model.stub'); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Resolve the fully-qualified path to the stub. |
186
|
|
|
* |
187
|
|
|
* @param string $stub |
188
|
|
|
* @return string |
189
|
|
|
*/ |
190
|
7 |
|
protected function resolveStubPath($stub) |
191
|
|
|
{ |
192
|
7 |
|
if ($this->useFallback()) { |
193
|
|
|
return parent::resolveStubPath($stub); |
194
|
|
|
} |
195
|
|
|
|
196
|
7 |
|
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) |
197
|
|
|
? $customPath |
198
|
7 |
|
: __DIR__ . $stub; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.