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 |
||
| 16 | class AdminController extends Controller |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Get page left navigation |
||
| 20 | * |
||
| 21 | * @return \Illuminate\Http\JsonResponse |
||
| 22 | */ |
||
| 23 | public function getMenu() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Component index page |
||
| 33 | * |
||
| 34 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 35 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 36 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 37 | */ |
||
| 38 | public function index(ComponentInterface $component) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Component list data |
||
| 49 | * |
||
| 50 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 51 | * @return mixed |
||
| 52 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 53 | */ |
||
| 54 | public function getList(ComponentInterface $component) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Component config data |
||
| 65 | * |
||
| 66 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 67 | * @return \Illuminate\Support\Collection |
||
| 68 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 69 | */ |
||
| 70 | public function config(ComponentInterface $component) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 81 | * @return null|\Sco\Admin\Contracts\Form\FormInterface |
||
| 82 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 83 | */ |
||
| 84 | public function getCreateInfo(ComponentInterface $component) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 97 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 98 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 99 | */ |
||
| 100 | public function create(ComponentInterface $component) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 111 | * @param \Illuminate\Http\Request $request |
||
| 112 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 113 | */ |
||
| 114 | public function store(ComponentInterface $component, Request $request) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 125 | * @param $id |
||
| 126 | * @return null|\Sco\Admin\Contracts\Form\FormInterface |
||
| 127 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 128 | */ |
||
| 129 | public function getEditInfo(ComponentInterface $component, $id) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 142 | * @param $id |
||
| 143 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 144 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 145 | */ |
||
| 146 | public function edit(ComponentInterface $component, $id) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 157 | * @param \Illuminate\Http\Request $request |
||
| 158 | * @param $id |
||
| 159 | * @return \Illuminate\Http\JsonResponse |
||
| 160 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 161 | */ |
||
| 162 | public function update(ComponentInterface $component, Request $request, $id) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 175 | * @param $id |
||
| 176 | * @return \Illuminate\Http\JsonResponse |
||
| 177 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 178 | */ |
||
| 179 | View Code Duplication | public function delete(ComponentInterface $component, $id) |
|
| 180 | { |
||
| 181 | if (! $component->isDelete()) { |
||
| 182 | throw new AuthorizationException(); |
||
| 183 | } |
||
| 184 | |||
| 185 | $component->delete($id); |
||
| 186 | |||
| 187 | return response()->json(['message' => 'ok']); |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 192 | * @param $id |
||
| 193 | * @return \Illuminate\Http\JsonResponse |
||
| 194 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 195 | */ |
||
| 196 | public function forceDelete(ComponentInterface $component, $id) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 209 | * @param $id |
||
| 210 | * @return \Illuminate\Http\JsonResponse |
||
| 211 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 212 | */ |
||
| 213 | public function restore(ComponentInterface $component, $id) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param \Sco\Admin\Contracts\ComponentInterface $component |
||
| 225 | * @return \Illuminate\Http\JsonResponse |
||
| 226 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 227 | */ |
||
| 228 | View Code Duplication | public function reorder(ComponentInterface $component) |
|
| 238 | } |
||
| 239 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.