@@ -143,6 +143,9 @@ discard block |
||
143 | 143 | return $nodes; |
144 | 144 | } |
145 | 145 | |
146 | + /** |
|
147 | + * @param string $key |
|
148 | + */ |
|
146 | 149 | protected function getTables($nodes, $key) { |
147 | 150 | $tables = []; |
148 | 151 | foreach($nodes as $node) { |
@@ -201,6 +204,12 @@ discard block |
||
201 | 204 | } |
202 | 205 | } |
203 | 206 | |
207 | + /** |
|
208 | + * @param string $type |
|
209 | + * @param string $command |
|
210 | + * @param string $model1 |
|
211 | + * @param string $model2 |
|
212 | + */ |
|
204 | 213 | protected function buildTables($type, $command, $model1, $model2, $tableAssignment) |
205 | 214 | { |
206 | 215 | foreach ($tableAssignment as $tables) { |
@@ -334,6 +343,10 @@ discard block |
||
334 | 343 | return $string; |
335 | 344 | } |
336 | 345 | |
346 | + /** |
|
347 | + * @param string $old |
|
348 | + * @param string $new |
|
349 | + */ |
|
337 | 350 | protected function convertArray($list, $old, $new) |
338 | 351 | { |
339 | 352 | return implode($new, array_filter(explode($old, $list), function($item){ |
@@ -398,11 +411,17 @@ discard block |
||
398 | 411 | return array(array(), $seen);//, array($item) |
399 | 412 | } |
400 | 413 | |
414 | + /** |
|
415 | + * @param string $message |
|
416 | + */ |
|
401 | 417 | protected function checkError($message, $model = "", $file = "") { |
402 | 418 | $this->checkErrors[] = array("message" => $message, "model" => $model, "file" => $file); |
403 | 419 | $this->checkedErrors++; |
404 | 420 | } |
405 | 421 | |
422 | + /** |
|
423 | + * @param string $message |
|
424 | + */ |
|
406 | 425 | protected function checkInfo($message, $model = "", $file = "") { |
407 | 426 | $this->checkInfo[] = array("message" => $message, "model" => $model, "file" => $file); |
408 | 427 | } |
@@ -416,6 +435,9 @@ discard block |
||
416 | 435 | } |
417 | 436 | } |
418 | 437 | |
438 | + /** |
|
439 | + * @param string $type |
|
440 | + */ |
|
419 | 441 | protected function checkRelations($relations, $type, $file, $model, $keys) { |
420 | 442 | if ($relations) { |
421 | 443 | $position = array_search($model, $keys); |
@@ -440,6 +462,9 @@ discard block |
||
440 | 462 | } |
441 | 463 | } |
442 | 464 | |
465 | + /** |
|
466 | + * @param string $rType |
|
467 | + */ |
|
443 | 468 | protected function checkPivotRelations($nodes, $relations, $rType) { |
444 | 469 | if ($relations) { |
445 | 470 | foreach($relations as $relation) { |
@@ -46,45 +46,45 @@ discard block |
||
46 | 46 | $morphTables = $this->uniqueArray($this->getTables($nodes, 'morphTables')); |
47 | 47 | |
48 | 48 | if (! $this->option('skip-check')) { |
49 | - $this->info('Checking Relationships...'); |
|
50 | - $keys = array_keys($nodes); |
|
51 | - foreach ($nodes as $model => $i) { |
|
52 | - $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
53 | - // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
54 | - } |
|
55 | - $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
56 | - $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
49 | + $this->info('Checking Relationships...'); |
|
50 | + $keys = array_keys($nodes); |
|
51 | + foreach ($nodes as $model => $i) { |
|
52 | + $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
53 | + // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
54 | + } |
|
55 | + $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
56 | + $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | if ($this->checkedErrors > 0) { |
60 | - $this->line(''); |
|
61 | - if ($this->option('check-only')) { |
|
62 | - $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
63 | - } |
|
64 | - $this->printErrors(); |
|
60 | + $this->line(''); |
|
61 | + if ($this->option('check-only')) { |
|
62 | + $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
63 | + } |
|
64 | + $this->printErrors(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
68 | 68 | if (! $this->option('check-only') && $this->checkedErrors > 0) { |
69 | - $this->line(''); |
|
70 | - $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
69 | + $this->line(''); |
|
70 | + $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
71 | 71 | } |
72 | 72 | if ($proceed) { |
73 | - $this->buildResources($nodes); |
|
73 | + $this->buildResources($nodes); |
|
74 | 74 | |
75 | - // if (!$this->option('no-migration')) { |
|
76 | - // $this->call('migrate'); // actually needed for pivot seeders ! |
|
77 | - // } |
|
75 | + // if (!$this->option('no-migration')) { |
|
76 | + // $this->call('migrate'); // actually needed for pivot seeders ! |
|
77 | + // } |
|
78 | 78 | |
79 | - $this->line(''); |
|
79 | + $this->line(''); |
|
80 | 80 | $this->buildTables('Pivot-Table', 'wn:pivot-table', 'model1', 'model2', $pivotTables); |
81 | 81 | |
82 | - $this->line(''); |
|
82 | + $this->line(''); |
|
83 | 83 | $this->buildTables('Morph-Table', 'wn:morph-table', 'model', 'morphable', $morphTables); |
84 | 84 | |
85 | - if (!$this->option('no-migration')) { |
|
86 | - $this->call('migrate'); |
|
87 | - } |
|
85 | + if (!$this->option('no-migration')) { |
|
86 | + $this->call('migrate'); |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -371,10 +371,10 @@ discard block |
||
371 | 371 | $deps = $this->getArgumentParser('relations')->parse($nodes[$key]['belongsTo']); |
372 | 372 | foreach($deps as $dependency) { |
373 | 373 | if(! $dependency['model']){ |
374 | - $dependency['model'] = $dependency['name']; |
|
375 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
376 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
377 | - } |
|
374 | + $dependency['model'] = $dependency['name']; |
|
375 | + } else if(strpos($dependency['model'], '\\') !== false ){ |
|
376 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
377 | + } |
|
378 | 378 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
379 | 379 | if ($dependency['model'] != $key) { |
380 | 380 | $tmp = $this->getDependencies($nodes, $dependency['model'], $seen); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $pivotTables = $this->uniqueArray($this->getTables($nodes, 'pivotTables')); |
46 | 46 | $morphTables = $this->uniqueArray($this->getTables($nodes, 'morphTables')); |
47 | 47 | |
48 | - if (! $this->option('skip-check')) { |
|
48 | + if (!$this->option('skip-check')) { |
|
49 | 49 | $this->info('Checking Relationships...'); |
50 | 50 | $keys = array_keys($nodes); |
51 | 51 | foreach ($nodes as $model => $i) { |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $this->printErrors(); |
65 | 65 | } |
66 | 66 | |
67 | - $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
68 | - if (! $this->option('check-only') && $this->checkedErrors > 0) { |
|
67 | + $proceed = (!$this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
68 | + if (!$this->option('check-only') && $this->checkedErrors > 0) { |
|
69 | 69 | $this->line(''); |
70 | 70 | $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
71 | 71 | } |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | |
99 | 99 | protected function readFile($file) |
100 | 100 | { |
101 | - $this->info("Reading file ".$file); |
|
101 | + $this->info("Reading file " . $file); |
|
102 | 102 | |
103 | 103 | $content = $this->fs->get($file); |
104 | 104 | $content = Yaml::parse($content); |
105 | 105 | |
106 | 106 | $nodes = []; |
107 | 107 | |
108 | - foreach ($content as $model => $i){ |
|
108 | + foreach ($content as $model => $i) { |
|
109 | 109 | /* |
110 | 110 | $i['modelname'] = as originally in YAML defined |
111 | 111 | $i['name'] = as originally defined in snake_case |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function mergeNodes($nodes, $toMerge, $forceRedefinition = false) { |
126 | - foreach($toMerge as $node) { |
|
126 | + foreach ($toMerge as $node) { |
|
127 | 127 | $nodes = $this->mergeNode($nodes, $node, $forceRedefinition); |
128 | 128 | } |
129 | 129 | |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | protected function mergeNode($nodes, $toMerge, $forceRedefinition = false) { |
134 | 134 | if (empty($nodes[$toMerge['uniquename']]) || $forceRedefinition) { |
135 | 135 | if (!empty($nodes[$toMerge['uniquename']])) { |
136 | - $this->checkError($toMerge['uniquename'] . ": forced to redefine (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", redefined from file ".$file.")"); |
|
136 | + $this->checkError($toMerge['uniquename'] . ": forced to redefine (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", redefined from file " . $file . ")"); |
|
137 | 137 | } |
138 | 138 | $nodes[$toMerge['uniquename']] = $toMerge; |
139 | 139 | } else { |
140 | - $this->checkError($toMerge['uniquename'] . ": already defined (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", trying to redefine from file ".$file."; Use --force-redefine to force redefinition)"); |
|
140 | + $this->checkError($toMerge['uniquename'] . ": already defined (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", trying to redefine from file " . $file . "; Use --force-redefine to force redefinition)"); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $nodes; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | protected function getTables($nodes, $key) { |
147 | 147 | $tables = []; |
148 | - foreach($nodes as $node) { |
|
148 | + foreach ($nodes as $node) { |
|
149 | 149 | if (!empty($node[$key])) { |
150 | 150 | $tables = array_merge($tables, $node[$key]); |
151 | 151 | } |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | protected function buildResources($nodes) |
158 | 158 | { |
159 | 159 | $modelIndex = 0; |
160 | - $migrationIdLength = strlen((string)count($nodes)); |
|
160 | + $migrationIdLength = strlen((string) count($nodes)); |
|
161 | 161 | foreach ($nodes as $i) { |
162 | - $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
163 | - $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
162 | + $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
163 | + $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex, $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
164 | 164 | |
165 | 165 | $this->line(''); |
166 | 166 | $this->info('Building Model ' . $i['uniquename']); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | protected function buildTables($type, $command, $model1, $model2, $tableAssignment) |
205 | 205 | { |
206 | 206 | foreach ($tableAssignment as $tables) { |
207 | - $this->info('Building '.$type.' ' . $tables[0] . ' - ' . $tables[1]); |
|
207 | + $this->info('Building ' . $type . ' ' . $tables[0] . ' - ' . $tables[1]); |
|
208 | 208 | $this->call($command, [ |
209 | 209 | $model1 => $tables[0], |
210 | 210 | $model2 => $tables[1], |
@@ -228,28 +228,28 @@ discard block |
||
228 | 228 | $i['modelname'] = $i['modelname']; |
229 | 229 | $i['uniquename'] = $i['uniquename']; |
230 | 230 | |
231 | - foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation){ |
|
232 | - if(isset($i[$relation])){ |
|
231 | + foreach (['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation) { |
|
232 | + if (isset($i[$relation])) { |
|
233 | 233 | $i[$relation] = $this->convertArray($i[$relation], ' ', ','); |
234 | 234 | } else { |
235 | 235 | $i[$relation] = false; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if($i['belongsToMany']){ |
|
239 | + if ($i['belongsToMany']) { |
|
240 | 240 | $i['pivotTables'] = $this->belongsTo($i['name'], $modelName, $i['belongsToMany']); |
241 | 241 | } |
242 | 242 | |
243 | - if($i['morphToMany']){ |
|
243 | + if ($i['morphToMany']) { |
|
244 | 244 | $i['morphTables'] = $this->morphToMany($modelName, $i['morphToMany']); |
245 | 245 | } |
246 | 246 | |
247 | - if($i['morphedByMany']){ |
|
247 | + if ($i['morphedByMany']) { |
|
248 | 248 | $i['morphTables'] = array_merge($i['morphTables'], $this->morphedByMany($i['name'], $modelName, $i['morphedByMany'])); |
249 | 249 | } |
250 | 250 | |
251 | 251 | $fields = []; |
252 | - foreach($i['fields'] as $name => $value) { |
|
252 | + foreach ($i['fields'] as $name => $value) { |
|
253 | 253 | $value['name'] = $name; |
254 | 254 | $fields[] = $this->serializeField($value); |
255 | 255 | } |
@@ -262,14 +262,14 @@ discard block |
||
262 | 262 | { |
263 | 263 | $parsedRelations = []; |
264 | 264 | $relations = $this->getArgumentParser('relations')->parse($belongsTo); |
265 | - foreach ($relations as $relation){ |
|
266 | - if(! $relation['model']){ |
|
265 | + foreach ($relations as $relation) { |
|
266 | + if (!$relation['model']) { |
|
267 | 267 | $table = snake_case($relation['name']); |
268 | 268 | } else { |
269 | 269 | $table = snake_case($this->extractClassName($relation['model'])); |
270 | 270 | } |
271 | 271 | |
272 | - $tables = [ str_singular($table), $name ]; |
|
272 | + $tables = [str_singular($table), $name]; |
|
273 | 273 | sort($tables); |
274 | 274 | $tables[] = $modelName; |
275 | 275 | $parsedRelations[] = $tables; |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | { |
283 | 283 | $parsedRelations = []; |
284 | 284 | $relations = $this->getArgumentParser('relations-morphMany')->parse(); |
285 | - foreach ($relations as $relation){ |
|
286 | - if(! $relation['through']){ |
|
285 | + foreach ($relations as $relation) { |
|
286 | + if (!$relation['through']) { |
|
287 | 287 | $morphable = snake_case($this->extractClassName($relation['model'])); |
288 | 288 | $model = snake_case($relation['name']); |
289 | 289 | } else { |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $model = snake_case($this->extractClassName($relation['model'])); |
292 | 292 | } |
293 | 293 | |
294 | - $tables = [ str_singular($model), str_singular($morphable), $modelName ]; |
|
294 | + $tables = [str_singular($model), str_singular($morphable), $modelName]; |
|
295 | 295 | $parsedRelations[] = $tables; |
296 | 296 | } |
297 | 297 | |
@@ -302,16 +302,16 @@ discard block |
||
302 | 302 | { |
303 | 303 | $parsedRelations = []; |
304 | 304 | $relations = $this->getArgumentParser('relations-morphMany')->parse($morphedByMany); |
305 | - foreach ($relations as $relation){ |
|
305 | + foreach ($relations as $relation) { |
|
306 | 306 | $table = ''; |
307 | 307 | |
308 | - if(! $relation['through']){ |
|
308 | + if (!$relation['through']) { |
|
309 | 309 | $morphable = snake_case($this->extractClassName($relation['model'])); |
310 | 310 | } else { |
311 | 311 | $morphable = snake_case($this->extractClassName($relation['through'])); |
312 | 312 | } |
313 | 313 | |
314 | - $tables = [ str_singular($name), str_singular($morphable), $modelName ]; |
|
314 | + $tables = [str_singular($name), str_singular($morphable), $modelName]; |
|
315 | 315 | $parsedRelations[] = $tables; |
316 | 316 | } |
317 | 317 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $string = "{$name};{$schema};{$rules};{$tags}"; |
329 | 329 | |
330 | - if(isset($field['factory']) && !empty($field['factory'])){ |
|
330 | + if (isset($field['factory']) && !empty($field['factory'])) { |
|
331 | 331 | $string .= ';' . $field['factory']; |
332 | 332 | } |
333 | 333 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | |
337 | 337 | protected function convertArray($list, $old, $new) |
338 | 338 | { |
339 | - return implode($new, array_filter(explode($old, $list), function($item){ |
|
339 | + return implode($new, array_filter(explode($old, $list), function($item) { |
|
340 | 340 | return !empty($item); |
341 | 341 | })); |
342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | $load_order = array(); |
346 | 346 | $seen = array(); |
347 | 347 | |
348 | - foreach($nodes as $key => $item) { |
|
348 | + foreach ($nodes as $key => $item) { |
|
349 | 349 | $tmp = $this->getDependencies($nodes, $key, $seen); |
350 | 350 | |
351 | 351 | // if($tmp[2] === false) { |
@@ -358,22 +358,22 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | private function getDependencies($nodes, $key, $seen = array()) { |
361 | - if(array_key_exists($key, $seen) === true) { |
|
361 | + if (array_key_exists($key, $seen) === true) { |
|
362 | 362 | return array(array(), $seen); |
363 | 363 | } |
364 | 364 | |
365 | 365 | |
366 | - if(!empty($nodes[$key])) { |
|
366 | + if (!empty($nodes[$key])) { |
|
367 | 367 | $order = array(); |
368 | 368 | // $failed = array(); |
369 | 369 | |
370 | - if($nodes[$key]['belongsTo']) { |
|
370 | + if ($nodes[$key]['belongsTo']) { |
|
371 | 371 | $deps = $this->getArgumentParser('relations')->parse($nodes[$key]['belongsTo']); |
372 | - foreach($deps as $dependency) { |
|
373 | - if(! $dependency['model']){ |
|
372 | + foreach ($deps as $dependency) { |
|
373 | + if (!$dependency['model']) { |
|
374 | 374 | $dependency['model'] = $dependency['name']; |
375 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
376 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
375 | + } else if (strpos($dependency['model'], '\\') !== false) { |
|
376 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\') + 1); // Cut offs first namespace part |
|
377 | 377 | } |
378 | 378 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
379 | 379 | if ($dependency['model'] != $key) { |
@@ -392,10 +392,10 @@ discard block |
||
392 | 392 | $order[$key] = $nodes[$key]; |
393 | 393 | // $failed = (count($failed) > 0) ? $failed : false; |
394 | 394 | |
395 | - return array($order, $seen);//, $failed |
|
395 | + return array($order, $seen); //, $failed |
|
396 | 396 | } |
397 | 397 | |
398 | - return array(array(), $seen);//, array($item) |
|
398 | + return array(array(), $seen); //, array($item) |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | protected function checkError($message, $model = "", $file = "") { |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | if ($relations) { |
421 | 421 | $position = array_search($model, $keys); |
422 | 422 | $relations = $this->getArgumentParser('relations')->parse($relations); |
423 | - foreach($relations as $relation) { |
|
424 | - switch($type) { |
|
423 | + foreach ($relations as $relation) { |
|
424 | + switch ($type) { |
|
425 | 425 | case "belongsTo": |
426 | 426 | $rModel = $relation['model'] ? $relation['model'] : $relation['name']; |
427 | 427 | break; |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | |
443 | 443 | protected function checkPivotRelations($nodes, $relations, $rType) { |
444 | 444 | if ($relations) { |
445 | - foreach($relations as $relation) { |
|
445 | + foreach ($relations as $relation) { |
|
446 | 446 | $relation['0'] = studly_case(str_singular($relation['0'])); |
447 | 447 | $relation['1'] = studly_case(str_singular($relation['1'])); |
448 | 448 | $relation['2'] = studly_case(str_singular($relation['2'])); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $snakeName = snake_case($name); |
25 | 25 | |
26 | 26 | $file = $this->option('file'); |
27 | - if (! $file) { |
|
27 | + if (!$file) { |
|
28 | 28 | $file = date('Y_m_d_His_') . $snakeName . '_table'; |
29 | 29 | $this->deleteOldMigration($snakeName); |
30 | 30 | } else { |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | |
47 | 47 | protected function deleteOldMigration($fileName) |
48 | 48 | { |
49 | - foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){ |
|
50 | - if($fileInfo->isDot()) continue; |
|
49 | + foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo) { |
|
50 | + if ($fileInfo->isDot()) continue; |
|
51 | 51 | |
52 | - if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){ |
|
52 | + if (strpos($fileInfo->getFilename(), $fileName) !== FALSE) { |
|
53 | 53 | unlink($fileInfo->getPathname()); |
54 | 54 | } |
55 | 55 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $name = $parts[0]['name']; |
93 | 93 | $parts[1]['args'] = array_merge(["'{$name}'"], $parts[1]['args']); |
94 | 94 | unset($parts[0]); |
95 | - $parts = array_map(function($part){ |
|
95 | + $parts = array_map(function($part) { |
|
96 | 96 | return '->' . $part['name'] . '(' . implode(', ', $part['args']) . ')'; |
97 | 97 | }, $parts); |
98 | 98 | return " \$table" . implode('', $parts) . ';'; |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function getConstraintDeclaration($key) |
117 | 117 | { |
118 | - if(! $key['column']){ |
|
118 | + if (!$key['column']) { |
|
119 | 119 | $key['column'] = 'id'; |
120 | 120 | } |
121 | - if(! $key['table']){ |
|
121 | + if (!$key['table']) { |
|
122 | 122 | $key['table'] = substr($key['name'], 0, count($key['name']) - 4); |
123 | 123 | } |
124 | 124 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ]) |
131 | 131 | ->get(); |
132 | 132 | |
133 | - if($key['on_delete']){ |
|
133 | + if ($key['on_delete']) { |
|
134 | 134 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
135 | 135 | ->with([ |
136 | 136 | 'event' => 'Delete', |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ->get(); |
140 | 140 | } |
141 | 141 | |
142 | - if($key['on_update']){ |
|
142 | + if ($key['on_update']) { |
|
143 | 143 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
144 | 144 | ->with([ |
145 | 145 | 'event' => 'Update', |
@@ -47,7 +47,9 @@ |
||
47 | 47 | protected function deleteOldMigration($fileName) |
48 | 48 | { |
49 | 49 | foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){ |
50 | - if($fileInfo->isDot()) continue; |
|
50 | + if($fileInfo->isDot()) { |
|
51 | + continue; |
|
52 | + } |
|
51 | 53 | |
52 | 54 | if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){ |
53 | 55 | unlink($fileInfo->getPathname()); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | class ModelCommand extends BaseCommand { |
5 | 5 | |
6 | - protected $signature = 'wn:model |
|
6 | + protected $signature = 'wn:model |
|
7 | 7 | {name : Name of the model.} |
8 | 8 | {--fillable= : the fillable fields.} |
9 | 9 | {--dates= : date fields.} |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | {--force= : override the existing files} |
25 | 25 | '; |
26 | 26 | |
27 | - protected $description = 'Generates a model class for a RESTfull resource'; |
|
27 | + protected $description = 'Generates a model class for a RESTfull resource'; |
|
28 | 28 | |
29 | 29 | public function handle() |
30 | 30 | { |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | |
50 | 50 | protected function getAsArrayFields($arg, $isOption = true) |
51 | 51 | { |
52 | - $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
52 | + $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
|
53 | 53 | if(is_string($arg)){ |
54 | - $arg = explode(',', $arg); |
|
54 | + $arg = explode(',', $arg); |
|
55 | 55 | } else if(! is_array($arg)) { |
56 | 56 | $arg = []; |
57 | 57 | } |
@@ -93,32 +93,32 @@ discard block |
||
93 | 93 | $template = $this->getTemplate($template); |
94 | 94 | foreach ($items as $item) { |
95 | 95 | $item['type'] = $type; |
96 | - if ($parser == 'relations') { |
|
97 | - $item['model'] = $this->prependNamespace($item['model'] ?: $item['name']); |
|
98 | - } else if ($parser != 'relations') { |
|
99 | - switch($type) { |
|
100 | - case "hasManyThrough": |
|
101 | - if(! $item['through'] && $item['model']){ |
|
102 | - $item['through'] = $this->prependNamespace($item['model']); |
|
103 | - $item['model'] = $this->prependNamespace($item['name']); |
|
104 | - } else { |
|
105 | - $item['through'] = $this->prependNamespace($item['through']); |
|
106 | - $item['model'] = $this->prependNamespace($item['model']); |
|
107 | - } |
|
108 | - break; |
|
109 | - case "morphMany": |
|
110 | - case "morphToMany": |
|
111 | - case "morphedByMany": |
|
112 | - if(! $item['through']){ |
|
113 | - $item['through'] = $item['model']; |
|
114 | - $item['model'] = $this->prependNamespace($item['name']); |
|
115 | - } else { |
|
116 | - $item['model'] = $this->prependNamespace($item['model']); |
|
117 | - } |
|
118 | - break; |
|
119 | - |
|
120 | - } |
|
121 | - } |
|
96 | + if ($parser == 'relations') { |
|
97 | + $item['model'] = $this->prependNamespace($item['model'] ?: $item['name']); |
|
98 | + } else if ($parser != 'relations') { |
|
99 | + switch($type) { |
|
100 | + case "hasManyThrough": |
|
101 | + if(! $item['through'] && $item['model']){ |
|
102 | + $item['through'] = $this->prependNamespace($item['model']); |
|
103 | + $item['model'] = $this->prependNamespace($item['name']); |
|
104 | + } else { |
|
105 | + $item['through'] = $this->prependNamespace($item['through']); |
|
106 | + $item['model'] = $this->prependNamespace($item['model']); |
|
107 | + } |
|
108 | + break; |
|
109 | + case "morphMany": |
|
110 | + case "morphToMany": |
|
111 | + case "morphedByMany": |
|
112 | + if(! $item['through']){ |
|
113 | + $item['through'] = $item['model']; |
|
114 | + $item['model'] = $this->prependNamespace($item['name']); |
|
115 | + } else { |
|
116 | + $item['model'] = $this->prependNamespace($item['model']); |
|
117 | + } |
|
118 | + break; |
|
119 | + |
|
120 | + } |
|
121 | + } |
|
122 | 122 | $relations[] = $template->with($item)->get(); |
123 | 123 | } |
124 | 124 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | protected function getRules() |
129 | 129 | { |
130 | 130 | $items = $this->parseValue($this->option('rules'), 'rules'); |
131 | - if ($items === false) { |
|
132 | - return $this->spaces(8) . "// Validation rules"; |
|
133 | - } |
|
131 | + if ($items === false) { |
|
132 | + return $this->spaces(8) . "// Validation rules"; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | $template = $this->getTemplate('model/rule'); |
136 | 136 | $rules = []; |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | protected function getAsArrayFields($arg, $isOption = true) |
51 | 51 | { |
52 | 52 | $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
53 | - if(is_string($arg)){ |
|
53 | + if (is_string($arg)) { |
|
54 | 54 | $arg = explode(',', $arg); |
55 | - } else if(! is_array($arg)) { |
|
55 | + } else if (!is_array($arg)) { |
|
56 | 56 | $arg = []; |
57 | 57 | } |
58 | - return implode(', ', array_map(function($item){ |
|
58 | + return implode(', ', array_map(function($item) { |
|
59 | 59 | return '"' . $item . '"'; |
60 | 60 | }, $arg)); |
61 | 61 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $this->getRelationsByType('morphedByMany', 'morphed-by-many', false, 'relations-morphMany') |
75 | 75 | ); |
76 | 76 | |
77 | - if(empty($relations)){ |
|
77 | + if (empty($relations)) { |
|
78 | 78 | return " // Relationships"; |
79 | 79 | } |
80 | 80 | |
@@ -85,20 +85,20 @@ discard block |
||
85 | 85 | { |
86 | 86 | $relations = []; |
87 | 87 | $option = $this->option($option); |
88 | - if($option){ |
|
88 | + if ($option) { |
|
89 | 89 | |
90 | 90 | $items = $this->getArgumentParser($parser)->parse($option); |
91 | 91 | |
92 | - $template = ($withTimestamps) ? 'model/relation-with-timestamps' : ($parser=='relations'?'model/relation':'model/relation-'.$type); |
|
92 | + $template = ($withTimestamps) ? 'model/relation-with-timestamps' : ($parser == 'relations' ? 'model/relation' : 'model/relation-' . $type); |
|
93 | 93 | $template = $this->getTemplate($template); |
94 | 94 | foreach ($items as $item) { |
95 | 95 | $item['type'] = $type; |
96 | 96 | if ($parser == 'relations') { |
97 | 97 | $item['model'] = $this->prependNamespace($item['model'] ?: $item['name']); |
98 | 98 | } else if ($parser != 'relations') { |
99 | - switch($type) { |
|
99 | + switch ($type) { |
|
100 | 100 | case "hasManyThrough": |
101 | - if(! $item['through'] && $item['model']){ |
|
101 | + if (!$item['through'] && $item['model']) { |
|
102 | 102 | $item['through'] = $this->prependNamespace($item['model']); |
103 | 103 | $item['model'] = $this->prependNamespace($item['name']); |
104 | 104 | } else { |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | case "morphMany": |
110 | 110 | case "morphToMany": |
111 | 111 | case "morphedByMany": |
112 | - if(! $item['through']){ |
|
112 | + if (!$item['through']) { |
|
113 | 113 | $item['through'] = $item['model']; |
114 | 114 | $item['model'] = $this->prependNamespace($item['name']); |
115 | 115 | } else { |