Conditions | 4 |
Paths | 2 |
Total Lines | 62 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php namespace Wn\Generators\Commands; |
||
24 | public function handle() |
||
25 | { |
||
26 | $this->parseFields(); |
||
27 | |||
28 | $resourceName = $this->argument('name'); |
||
29 | $modelName = ucwords(camel_case($resourceName)); |
||
|
|||
30 | $tableName = str_plural($resourceName); |
||
31 | |||
32 | // generating the model |
||
33 | $this->call('wn:model', [ |
||
34 | 'name' => $modelName, |
||
35 | '--fillable' => $this->fieldsHavingTag('fillable'), |
||
36 | '--dates' => $this->fieldsHavingTag('date'), |
||
37 | '--has-many' => $this->option('has-many'), |
||
38 | '--has-one' => $this->option('has-one'), |
||
39 | '--belongs-to' => $this->option('belongs-to'), |
||
40 | '--belongs-to-many' => $this->option('belongs-to-many'), |
||
41 | '--rules' => $this->rules(), |
||
42 | '--path' => $this->option('path'), |
||
43 | '--force' => $this->option('force'), |
||
44 | '--timestamps' => $this->hasTimestamps() ? 'true' : 'false', |
||
45 | '--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false', |
||
46 | '--parsed' => true |
||
47 | ]); |
||
48 | |||
49 | // generating the migration |
||
50 | $this->call('wn:migration', [ |
||
51 | 'table' => $tableName, |
||
52 | '--schema' => $this->schema(), |
||
53 | '--keys' => $this->migrationKeys(), |
||
54 | '--file' => $this->option('migration-file'), |
||
55 | '--force' => $this->option('force'), |
||
56 | '--add' => $this->option('add'), |
||
57 | '--parsed' => true |
||
58 | ]); |
||
59 | |||
60 | // generating REST actions trait if doesn't exist |
||
61 | if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
||
62 | $this->call('wn:controller:rest-actions'); |
||
63 | } |
||
64 | |||
65 | // generating the controller and routes |
||
66 | $this->call('wn:controller', [ |
||
67 | 'model' => $modelName, |
||
68 | '--force' => $this->option('force'), |
||
69 | '--no-routes' => false |
||
70 | ]); |
||
71 | |||
72 | // generating model factory |
||
73 | $this->call('wn:factory', [ |
||
74 | 'model' => 'App\\' . $modelName, |
||
75 | '--fields' => $this->factoryFields(), |
||
76 | '--force' => $this->option('force'), |
||
77 | '--parsed' => true |
||
78 | ]); |
||
79 | |||
80 | // generating database seeder |
||
81 | // $this->call('wn:seeder', [ |
||
82 | // 'model' => 'App\\' . $modelName |
||
83 | // ]); |
||
84 | |||
85 | } |
||
86 | |||
202 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.