@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | protected $signature = 'wn:controller |
8 | 8 | {model : Name of the model (with namespace if not App)} |
9 | - {--path='.ControllerCommand::DEFAULT_PATH.' : where to store the controllers file.} |
|
9 | + {--path='.ControllerCommand::DEFAULT_PATH . ' : where to store the controllers file.} |
|
10 | 10 | {--no-routes= : without routes} |
11 | 11 | {--routes= : where to store the routes.} |
12 | 12 | {--force= : override the existing files} |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | $model = $this->argument('model'); |
21 | 21 | $name = ''; |
22 | - if(strrpos($model, "\\") === false){ |
|
22 | + if (strrpos($model, "\\") === false) { |
|
23 | 23 | $name = $model; |
24 | 24 | $model = "App\\" . $model; |
25 | 25 | } else { |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | 'name' => $controller, |
33 | 33 | 'model' => $model, |
34 | 34 | 'namespace' => $this->getNamespace(), |
35 | - 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
35 | + 'use' => ($this->getNamespace() != $this->getDefaultNamespace() ? 'use ' . $this->getDefaultNamespace() . '\Controller;' . PHP_EOL . 'use ' . $this->getDefaultNamespace() . '\RESTActions;' . PHP_EOL : '') |
|
36 | 36 | ]) |
37 | 37 | ->get(); |
38 | 38 | |
39 | 39 | $this->save($content, "./{$this->option('path')}/{$controller}.php", "{$controller}"); |
40 | 40 | |
41 | - if (! $this->option('no-routes')) { |
|
41 | + if (!$this->option('no-routes')) { |
|
42 | 42 | $options = [ |
43 | 43 | 'resource' => snake_case($name, '-'), |
44 | 44 | '--controller' => $controller, |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | '--parsed' => true |
75 | 75 | ]); |
76 | 76 | |
77 | - if (! $this->option('no-controller')) { |
|
77 | + if (!$this->option('no-controller')) { |
|
78 | 78 | // generating REST actions trait if doesn't exist |
79 | - if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
|
79 | + if (!$this->fs->exists('./app/Http/Controllers/RESTActions.php')) { |
|
80 | 80 | $this->call('wn:controller:rest-actions'); |
81 | 81 | } |
82 | 82 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | |
101 | 101 | // generating model factory |
102 | 102 | $this->call('wn:factory', [ |
103 | - 'model' => $this->getNamespace().'\\'.$modelName, |
|
104 | - '--file' => './database/factories/'.str_plural($modelName).'.php', |
|
103 | + 'model' => $this->getNamespace() . '\\' . $modelName, |
|
104 | + '--file' => './database/factories/' . str_plural($modelName) . '.php', |
|
105 | 105 | '--fields' => $this->factoryFields(), |
106 | 106 | '--force' => $this->option('force'), |
107 | 107 | '--parsed' => true |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | protected function parseFields() |
118 | 118 | { |
119 | 119 | $fields = $this->argument('fields'); |
120 | - if($this->option('parsed')){ |
|
120 | + if ($this->option('parsed')) { |
|
121 | 121 | $this->fields = $fields; |
122 | 122 | } else { |
123 | - if(! $fields){ |
|
123 | + if (!$fields) { |
|
124 | 124 | $this->fields = []; |
125 | 125 | } else { |
126 | 126 | $this->fields = $this->getArgumentParser('fields') |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | if ($name['nullable']) { |
152 | 152 | $return['schema'][] = ['name' => 'nullable', 'args' => []]; |
153 | 153 | } else { |
154 | - $return['rules'] = 'required'.(!empty($return['rules'])?'|'.$return['rules']:''); |
|
154 | + $return['rules'] = 'required' . (!empty($return['rules']) ? '|' . $return['rules'] : ''); |
|
155 | 155 | } |
156 | 156 | } else { |
157 | 157 | $return['schema'] = [ |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | protected function fieldsHavingTag($tag) |
172 | 172 | { |
173 | - return array_map(function($field){ |
|
173 | + return array_map(function($field) { |
|
174 | 174 | return $field['name']; |
175 | 175 | }, array_filter($this->fields, function($field) use($tag){ |
176 | 176 | return in_array($tag, $field['tags']); |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | |
180 | 180 | protected function rules() |
181 | 181 | { |
182 | - return array_map(function($field){ |
|
182 | + return array_map(function($field) { |
|
183 | 183 | return [ |
184 | 184 | 'name' => $field['name'], |
185 | 185 | 'rule' => $field['rules'] |
186 | 186 | ]; |
187 | - }, array_filter($this->fields, function($field){ |
|
187 | + }, array_filter($this->fields, function($field) { |
|
188 | 188 | return !empty($field['rules']); |
189 | 189 | })); |
190 | 190 | } |
191 | 191 | |
192 | 192 | protected function schema() |
193 | 193 | { |
194 | - return array_map(function($field){ |
|
194 | + return array_map(function($field) { |
|
195 | 195 | return array_merge([[ |
196 | 196 | 'name' => $field['name'], |
197 | 197 | 'args' => [] |
@@ -204,19 +204,19 @@ discard block |
||
204 | 204 | $belongsTo = $this->option('belongs-to'); |
205 | 205 | $morphTo = $this->option('morph-to'); |
206 | 206 | |
207 | - if(! $belongsTo && (! $withMorph || ! $morphTo)) { |
|
207 | + if (!$belongsTo && (!$withMorph || !$morphTo)) { |
|
208 | 208 | return []; |
209 | 209 | } |
210 | 210 | |
211 | 211 | $belongsTo = $belongsTo ? $this->getArgumentParser('relations')->parse($belongsTo) : []; |
212 | 212 | |
213 | - $belongsTo = array_map(function($relation){ |
|
213 | + $belongsTo = array_map(function($relation) { |
|
214 | 214 | return array("model" => camel_case(str_singular($this->extractClassName($relation['model'] ? $relation['model'] : $relation['name']))), "name" => snake_case(str_singular($this->extractClassName($relation['name']))) . '_id', "type" => "belongsTo"); |
215 | 215 | }, $belongsTo); |
216 | 216 | |
217 | 217 | if ($withMorph) { |
218 | 218 | $morphTo = $morphTo ? $this->getArgumentParser('relations-morphTo')->parse($morphTo) : []; |
219 | - $morphTo = array_map(function($relation){ |
|
219 | + $morphTo = array_map(function($relation) { |
|
220 | 220 | $name = snake_case(str_singular($relation['name'])); |
221 | 221 | return array(array("name" => $name . '_id', "type" => "morphTo", "nullable" => $relation['nullable']), array("name" => $name . '_type', "type" => "morphTo", "nullable" => $relation['nullable'])); |
222 | 222 | }, $morphTo); |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | |
246 | 246 | protected function factoryFields() |
247 | 247 | { |
248 | - return array_map(function($field){ |
|
248 | + return array_map(function($field) { |
|
249 | 249 | return [ |
250 | 250 | 'name' => $field['name'], |
251 | 251 | 'type' => $field['factory'] |
252 | 252 | ]; |
253 | - }, array_filter($this->fields, function($field){ |
|
253 | + }, array_filter($this->fields, function($field) { |
|
254 | 254 | return isset($field['factory']) && $field['factory']; |
255 | 255 | })); |
256 | 256 | } |