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 |
||
| 11 | class PublishAdminLTE extends Command |
||
| 12 | { |
||
| 13 | use Installable; |
||
| 14 | /** |
||
| 15 | * The filesystem instance. |
||
| 16 | * |
||
| 17 | * @var \Illuminate\Filesystem\Filesystem |
||
| 18 | */ |
||
| 19 | protected $files; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The name and signature of the console command. |
||
| 23 | */ |
||
| 24 | protected $signature = 'adminlte-laravel:publish {--f|force : Force overwrite of files}'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The console command description. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $description = 'Publish Acacha AdminLTE Template files into laravel project'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Force overwrite of files. |
||
| 35 | * |
||
| 36 | * @var bool |
||
| 37 | */ |
||
| 38 | protected $force = false; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Create a new command instance. |
||
| 42 | * |
||
| 43 | * @param \Illuminate\Filesystem\Filesystem $files |
||
| 44 | * |
||
| 45 | * @return void |
||
|
|
|||
| 46 | */ |
||
| 47 | public function __construct(Filesystem $files) |
||
| 48 | { |
||
| 49 | parent::__construct(); |
||
| 50 | $this->files = $files; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Execute the console command. |
||
| 55 | */ |
||
| 56 | View Code Duplication | public function handle() |
|
| 57 | { |
||
| 58 | $this->processOptions(); |
||
| 59 | $this->publishHomeController(); |
||
| 60 | $this->changeRegisterController(); |
||
| 61 | $this->changeLoginController(); |
||
| 62 | $this->changeForgotPasswordController(); |
||
| 63 | $this->changeResetPasswordController(); |
||
| 64 | $this->publishPublicAssets(); |
||
| 65 | $this->publishViews(); |
||
| 66 | $this->publishResourceAssets(); |
||
| 67 | $this->publishTests(); |
||
| 68 | $this->publishLanguages(); |
||
| 69 | $this->publishGravatar(); |
||
| 70 | $this->publishConfig(); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Install Home Controller. |
||
| 75 | */ |
||
| 76 | private function publishHomeController() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Change Auth Register controller. |
||
| 83 | */ |
||
| 84 | private function changeRegisterController() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Change Auth Login controller. |
||
| 91 | */ |
||
| 92 | private function changeLoginController() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Change Auth Forgot Password controller. |
||
| 99 | */ |
||
| 100 | private function changeForgotPasswordController() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Change Auth Reset Password controller. |
||
| 107 | */ |
||
| 108 | private function changeResetPasswordController() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Install public assets. |
||
| 115 | */ |
||
| 116 | private function publishPublicAssets() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Install views. |
||
| 123 | */ |
||
| 124 | private function publishViews() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Install resource assets. |
||
| 131 | */ |
||
| 132 | private function publishResourceAssets() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Install resource assets. |
||
| 139 | */ |
||
| 140 | private function publishTests() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Install language assets. |
||
| 147 | */ |
||
| 148 | private function publishLanguages() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Install gravatar config file. |
||
| 155 | */ |
||
| 156 | private function publishGravatar() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Publish adminlte package config. |
||
| 163 | */ |
||
| 164 | private function publishConfig() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Process options before running command. |
||
| 171 | */ |
||
| 172 | private function processOptions() |
||
| 176 | } |
||
| 177 |
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.