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 |
||
| 14 | class PublishAdminLTE extends Command |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The filesystem instance. |
||
| 18 | * |
||
| 19 | * @var \Illuminate\Filesystem\Filesystem |
||
| 20 | */ |
||
| 21 | protected $files; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The name and signature of the console command. |
||
| 25 | */ |
||
| 26 | protected $signature = 'adminlte-laravel:publish {--f|force : Force overwrite of files}'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The console command description. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $description = 'Publish Acacha AdminLTE Template files into laravel project'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Force overwrite of files. |
||
| 37 | * |
||
| 38 | * @var boolean |
||
| 39 | */ |
||
| 40 | protected $force = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Create a new command instance. |
||
| 44 | * |
||
| 45 | * @param \Illuminate\Filesystem\Filesystem $files |
||
| 46 | * |
||
| 47 | * @return void |
||
|
|
|||
| 48 | */ |
||
| 49 | public function __construct(Filesystem $files) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Execute the console command. |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function handle() |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Install Home Controller. |
||
| 74 | */ |
||
| 75 | private function publishHomeController() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Install Auth controller. |
||
| 82 | */ |
||
| 83 | private function changeRegisterController() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Install public assets. |
||
| 90 | */ |
||
| 91 | private function publishPublicAssets() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Install views. |
||
| 98 | */ |
||
| 99 | private function publishViews() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Install resource assets. |
||
| 106 | */ |
||
| 107 | private function publishResourceAssets() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Install resource assets. |
||
| 114 | */ |
||
| 115 | private function publishTests() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Install language assets. |
||
| 122 | */ |
||
| 123 | private function publishLanguages() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Install gravatar config file. |
||
| 130 | */ |
||
| 131 | private function publishGravatar() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Install files from array. |
||
| 138 | * |
||
| 139 | * @param $files |
||
| 140 | */ |
||
| 141 | private function install($files) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param $fileName |
||
| 159 | * @param string $prompt |
||
| 160 | * |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | protected function confirmOverwrite($fileName, $prompt = '') |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Create the directory to house the published files if needed. |
||
| 174 | * |
||
| 175 | * @param string $directory |
||
| 176 | * |
||
| 177 | * @return void |
||
| 178 | */ |
||
| 179 | protected function createParentDirectory($directory) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Publish the file to the given path. |
||
| 188 | * |
||
| 189 | * @param string $from |
||
| 190 | * @param string $to |
||
| 191 | * |
||
| 192 | * @return void |
||
| 193 | */ |
||
| 194 | protected function publishFile($from, $to) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Publish the directory to the given directory. |
||
| 203 | * |
||
| 204 | * @param string $from |
||
| 205 | * @param string $to |
||
| 206 | * |
||
| 207 | * @return void |
||
| 208 | */ |
||
| 209 | protected function publishDirectory($from, $to) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Write a status message to the console. |
||
| 225 | * |
||
| 226 | * @param string $from |
||
| 227 | * @param string $to |
||
| 228 | * @param string $type |
||
| 229 | * |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | protected function status($from, $to, $type) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Process options before running command |
||
| 241 | */ |
||
| 242 | private function processOptions() |
||
| 246 | } |
||
| 247 |
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.