| Conditions | 4 |
| Paths | 4 |
| Total Lines | 66 |
| 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; |
||
| 29 | public function handle() |
||
| 30 | { |
||
| 31 | $this->parseFields(); |
||
| 32 | |||
| 33 | $resourceName = $this->argument('name'); |
||
| 34 | $modelName = ucwords(Str::camel($resourceName)); |
||
|
|
|||
| 35 | $tableName = Str::plural($resourceName); |
||
| 36 | |||
| 37 | // generating the model |
||
| 38 | $this->call('wn:model', [ |
||
| 39 | 'name' => $modelName, |
||
| 40 | '--fillable' => $this->fieldsHavingTag('fillable'), |
||
| 41 | '--guarded' => $this->fieldsHavingTag('guarded'), |
||
| 42 | '--dates' => $this->fieldsHavingTag('date'), |
||
| 43 | '--has-many' => $this->option('has-many'), |
||
| 44 | '--has-one' => $this->option('has-one'), |
||
| 45 | '--belongs-to' => $this->option('belongs-to'), |
||
| 46 | '--belongs-to-many' => $this->option('belongs-to-many'), |
||
| 47 | '--images' => $this->option('images'), |
||
| 48 | '--rules' => $this->rules(), |
||
| 49 | '--path' => $this->option('path'), |
||
| 50 | '--force' => $this->option('force'), |
||
| 51 | '--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false', |
||
| 52 | '--parsed' => true |
||
| 53 | ]); |
||
| 54 | |||
| 55 | // generating the migration |
||
| 56 | $this->call('wn:migration', [ |
||
| 57 | 'table' => $tableName, |
||
| 58 | '--schema' => $this->schema(), |
||
| 59 | '--keys' => $this->migrationKeys(), |
||
| 60 | '--file' => $this->option('migration-file'), |
||
| 61 | '--force' => $this->option('force'), |
||
| 62 | '--add' => $this->option('add'), |
||
| 63 | '--parsed' => true |
||
| 64 | ]); |
||
| 65 | |||
| 66 | // generating REST actions trait if doesn't exist |
||
| 67 | if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
||
| 68 | $this->call('wn:controller:rest-actions'); |
||
| 69 | } |
||
| 70 | // generating the controller and routes |
||
| 71 | $controllerOptions = [ |
||
| 72 | 'model' => $modelName, |
||
| 73 | '--force' => $this->option('force'), |
||
| 74 | '--no-routes' => false, |
||
| 75 | ]; |
||
| 76 | if ($this->option('laravel')) { |
||
| 77 | $controllerOptions['--laravel'] = true; |
||
| 78 | } |
||
| 79 | $this->call('wn:controller', $controllerOptions); |
||
| 80 | |||
| 81 | // generating model factory |
||
| 82 | $this->call('wn:factory', [ |
||
| 83 | 'model' => 'App\\' . $modelName, |
||
| 84 | '--fields' => $this->factoryFields(), |
||
| 85 | '--force' => $this->option('force'), |
||
| 86 | '--parsed' => true |
||
| 87 | ]); |
||
| 88 | |||
| 89 | // generating database seeder |
||
| 90 | // $this->call('wn:seeder', [ |
||
| 91 | // 'model' => 'App\\' . $modelName |
||
| 92 | // ]); |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 211 |
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.