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 |
||
| 13 | class GenerateDocumentation extends Command |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * The name and signature of the console command. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $signature = 'api:generate |
||
| 21 | {--output=public/docs : The output path for the generated documentation} |
||
| 22 | {--routePrefix= : The route prefix to use for generation} |
||
| 23 | {--routes=* : The route names to use for generation} |
||
| 24 | {--actAsUserId= : The user ID to use for API response calls} |
||
| 25 | {--router=laravel : The router to be used (Laravel or Dingo)} |
||
| 26 | {--bindings= : Route Model Bindings} |
||
| 27 | '; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The console command description. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $description = 'Generate your API documentation from existing Laravel routes.'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Create a new command instance. |
||
| 38 | * |
||
| 39 | * @return void |
||
|
|
|||
| 40 | */ |
||
| 41 | public function __construct() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Execute the console command. |
||
| 48 | * |
||
| 49 | * @return false|null |
||
| 50 | */ |
||
| 51 | public function handle() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param Collection $parsedRoutes |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | private function writeMarkdown($parsedRoutes) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | private function getBindings() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param $actAs |
||
| 128 | */ |
||
| 129 | private function setUserToBeImpersonated($actAs) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return mixed |
||
| 146 | */ |
||
| 147 | private function getRoutes() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param AbstractGenerator $generator |
||
| 158 | * @param $allowedRoutes |
||
| 159 | * @param $routePrefix |
||
| 160 | * @return array |
||
| 161 | */ |
||
| 162 | View Code Duplication | private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * @param AbstractGenerator $generator |
||
| 178 | * @param $allowedRoutes |
||
| 179 | * @param $routePrefix |
||
| 180 | * @return array |
||
| 181 | */ |
||
| 182 | View Code Duplication | private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) |
|
| 195 | } |
||
| 196 |
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.