Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php namespace Wn\Generators\Commands; |
||
| 4 | class ModelCommand extends BaseCommand { |
||
| 5 | |||
| 6 | protected $signature = 'wn:model |
||
| 7 | {name : Name of the model.} |
||
| 8 | {--fillable= : the fillable fields.} |
||
| 9 | {--dates= : date fields.} |
||
| 10 | {--has-many= : hasMany relationships.} |
||
| 11 | {--has-one= : hasOne relationships.} |
||
| 12 | {--belongs-to= : belongsTo relationships.} |
||
| 13 | {--belongs-to-many= : belongsToMany relationships.} |
||
| 14 | {--rules= : fields validation rules.} |
||
| 15 | {--timestamps=true : enables timestamps on the model.} |
||
| 16 | {--path=app : where to store the model php file.} |
||
| 17 | {--soft-deletes= : adds SoftDeletes trait to the model.} |
||
| 18 | {--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options} |
||
| 19 | {--force= : override the existing files} |
||
| 20 | '; |
||
| 21 | |||
| 22 | protected $description = 'Generates a model class for a RESTfull resource'; |
||
| 23 | |||
| 24 | public function handle() |
||
| 44 | |||
| 45 | protected function getAsArrayFields($arg, $isOption = true) |
||
| 57 | |||
| 58 | protected function getNamespace() |
||
| 62 | |||
| 63 | protected function getRelations() |
||
| 78 | |||
| 79 | protected function getRelationsByType($type, $option, $withTimestamps = false) |
||
| 101 | |||
| 102 | View Code Duplication | protected function getRules() |
|
| 120 | |||
| 121 | protected function getAdditional() |
||
| 127 | |||
| 128 | protected function getUses() |
||
| 134 | |||
| 135 | } |
||
| 136 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.