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 |
||
| 7 | class MakeJsonApiDemoRemove extends Command |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * The name and signature of the console command. |
||
| 11 | * |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $signature = 'make:demo-remove'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The console command description. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $description = 'Remove JsonApi Demo entities'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected $controllers = [ |
||
| 27 | 'LikesController.stub' => 'LikesController.php', |
||
| 28 | 'SkillsController.stub' => 'SkillsController.php', |
||
| 29 | 'TeamsController.stub' => 'TeamsController.php', |
||
| 30 | 'UsersController.stub' => 'UsersController.php' |
||
| 31 | ]; |
||
| 32 | |||
| 33 | protected $models = [ |
||
| 34 | 'Like.stub' => 'Like.php', |
||
| 35 | 'Skill.stub' => 'Skill.php', |
||
| 36 | 'Team.stub' => 'Team.php' |
||
| 37 | ]; |
||
| 38 | |||
| 39 | protected $migrations = [ |
||
| 40 | 'create_likes_table.stub' => 'create_likes_table.php', |
||
| 41 | 'create_membership_table.stub' => 'create_membership_table.php', |
||
| 42 | 'create_skills_table.stub' => 'create_skills_table.php', |
||
| 43 | 'create_teams_table.stub' => 'create_teams_table.php', |
||
| 44 | 'add_foreign_keys_to_likes_table.stub' => 'add_foreign_keys_to_likes_table.php', |
||
| 45 | 'add_foreign_keys_to_membership_table.stub' => 'add_foreign_keys_to_membership_table.php', |
||
| 46 | 'add_foreign_keys_to_skills_table.stub' => 'add_foreign_keys_to_skills_table.php', |
||
| 47 | 'add_foreign_keys_to_teams_table.stub' => 'add_foreign_keys_to_teams_table.php' |
||
| 48 | ]; |
||
| 49 | |||
| 50 | protected $seeds = [ |
||
| 51 | 'TeamsTableSeeder.stub' => 'TeamsTableSeeder.php', |
||
| 52 | 'TeamUsersTableSeeder.stub' => 'TeamUsersTableSeeder.php', |
||
| 53 | 'JsonApiSeeder.stub' => 'JsonApiSeeder.php' |
||
| 54 | ]; |
||
| 55 | |||
| 56 | protected $jsonapiEntities = [ |
||
| 57 | 'JsonApi/Likes/Hydrator.stub' => 'JsonApi/Likes/Hydrator.php', |
||
| 58 | 'JsonApi/Likes/Request.stub' => 'JsonApi/Likes/Request.php', |
||
| 59 | 'JsonApi/Likes/Schema.stub' => 'JsonApi/Likes/Schema.php', |
||
| 60 | 'JsonApi/Likes/Search.stub' => 'JsonApi/Likes/Search.php', |
||
| 61 | 'JsonApi/Likes/Validators.stub' => 'JsonApi/Likes/Validators.php', |
||
| 62 | |||
| 63 | 'JsonApi/Skills/Hydrator.stub' => 'JsonApi/Skills/Hydrator.php', |
||
| 64 | 'JsonApi/Skills/Request.stub' => 'JsonApi/Skills/Request.php', |
||
| 65 | 'JsonApi/Skills/Schema.stub' => 'JsonApi/Skills/Schema.php', |
||
| 66 | 'JsonApi/Skills/Search.stub' => 'JsonApi/Skills/Search.php', |
||
| 67 | 'JsonApi/Skills/Validators.stub' => 'JsonApi/Skills/Validators.php', |
||
| 68 | |||
| 69 | 'JsonApi/Teams/Hydrator.stub' => 'JsonApi/Teams/Hydrator.php', |
||
| 70 | 'JsonApi/Teams/Request.stub' => 'JsonApi/Teams/Request.php', |
||
| 71 | 'JsonApi/Teams/Schema.stub' => 'JsonApi/Teams/Schema.php', |
||
| 72 | 'JsonApi/Teams/Search.stub' => 'JsonApi/Teams/Search.php', |
||
| 73 | 'JsonApi/Teams/Validators.stub' => 'JsonApi/Teams/Validators.php', |
||
| 74 | |||
| 75 | 'JsonApi/Users/Hydrator.stub' => 'JsonApi/Users/Hydrator.php', |
||
| 76 | 'JsonApi/Users/Request.stub' => 'JsonApi/Users/Request.php', |
||
| 77 | 'JsonApi/Users/Schema.stub' => 'JsonApi/Users/Schema.php', |
||
| 78 | 'JsonApi/Users/Search.stub' => 'JsonApi/Users/Search.php', |
||
| 79 | 'JsonApi/Users/Validators.stub' => 'JsonApi/Users/Validators.php', |
||
| 80 | ]; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Create a new command instance. |
||
| 84 | * |
||
| 85 | * @return void |
||
|
|
|||
| 86 | */ |
||
| 87 | public function __construct() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Execute the console command. |
||
| 94 | * |
||
| 95 | * @return mixed |
||
| 96 | */ |
||
| 97 | public function handle() |
||
| 110 | |||
| 111 | View Code Duplication | protected function removeModels() |
|
| 119 | |||
| 120 | View Code Duplication | protected function removeControllers() |
|
| 128 | |||
| 129 | protected function removeMigrations() |
||
| 136 | |||
| 137 | protected function removeSeeds() |
||
| 145 | |||
| 146 | protected function removeJsonApiEntities() |
||
| 172 | } |
||
| 173 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.