Conditions | 8 |
Paths | 17 |
Total Lines | 80 |
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; |
||
36 | public function handle() |
||
37 | { |
||
38 | $this->parseFields(); |
||
39 | |||
40 | $resourceName = $this->argument('name'); |
||
41 | $modelName = ucwords(camel_case($resourceName)); |
||
|
|||
42 | $tableName = snake_case(str_plural($resourceName)); |
||
43 | |||
44 | // generating the model |
||
45 | $this->call('wn:model', [ |
||
46 | 'name' => $modelName, |
||
47 | '--fillable' => $this->fieldsHavingTag('fillable'), |
||
48 | '--dates' => $this->fieldsHavingTag('date'), |
||
49 | '--has-many' => $this->option('has-many'), |
||
50 | '--has-one' => $this->option('has-one'), |
||
51 | '--belongs-to' => $this->option('belongs-to'), |
||
52 | '--belongs-to-many' => $this->option('belongs-to-many'), |
||
53 | '--has-many-through' => $this->option('has-many-through'), |
||
54 | '--morph-to' => $this->option('morph-to'), |
||
55 | '--morph-many' => $this->option('morph-many'), |
||
56 | '--morph-to-many' => $this->option('morph-to-many'), |
||
57 | '--morphed-by-many' => $this->option('morphed-by-many'), |
||
58 | '--rules' => $this->rules(), |
||
59 | '--path' => $this->option('path'), |
||
60 | '--force' => $this->option('force'), |
||
61 | '--timestamps' => $this->hasTimestamps() ? 'true' : 'false', |
||
62 | '--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false', |
||
63 | '--parsed' => true |
||
64 | ]); |
||
65 | |||
66 | // generating the migration |
||
67 | $this->call('wn:migration', [ |
||
68 | 'table' => $tableName, |
||
69 | '--schema' => $this->schema(), |
||
70 | '--keys' => $this->migrationKeys(), |
||
71 | '--file' => $this->option('migration-file'), |
||
72 | '--force' => $this->option('force'), |
||
73 | '--add' => $this->option('add'), |
||
74 | '--parsed' => true |
||
75 | ]); |
||
76 | |||
77 | if (! $this->option('no-controller')) { |
||
78 | // generating REST actions trait if doesn't exist |
||
79 | if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
||
80 | $this->call('wn:controller:rest-actions'); |
||
81 | } |
||
82 | |||
83 | // generating the controller and routes |
||
84 | $controllerOptions = [ |
||
85 | 'model' => $modelName, |
||
86 | '--force' => $this->option('force'), |
||
87 | '--no-routes' => $this->option('no-routes'), |
||
88 | ]; |
||
89 | if ($this->option('laravel')) { |
||
90 | $controllerOptions['--laravel'] = true; |
||
91 | } |
||
92 | if ($this->option('routes')) { |
||
93 | $controllerOptions['--routes'] = $this->option('routes'); |
||
94 | } |
||
95 | if ($this->option('controller')) { |
||
96 | $controllerOptions['--path'] = $this->option('controller'); |
||
97 | } |
||
98 | $this->call('wn:controller', $controllerOptions); |
||
99 | } |
||
100 | |||
101 | // generating model factory |
||
102 | $this->call('wn:factory', [ |
||
103 | 'model' => $this->getNamespace().'\\'.$modelName, |
||
104 | '--file' => './database/factories/'.str_plural($modelName).'.php', |
||
105 | '--fields' => $this->factoryFields(), |
||
106 | '--force' => $this->option('force'), |
||
107 | '--parsed' => true |
||
108 | ]); |
||
109 | |||
110 | // generating database seeder |
||
111 | // $this->call('wn:seeder', [ |
||
112 | // 'model' => 'App\\' . $modelName |
||
113 | // ]); |
||
114 | |||
115 | } |
||
116 | |||
281 |
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.