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 |
||
| 15 | class QueryController extends Controller |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Show view |
||
| 19 | * |
||
| 20 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 21 | */ |
||
| 22 | public function index() { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Get from cache |
||
| 28 | * |
||
| 29 | * |
||
| 30 | * @param Request $request |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public function get(Request $request): array |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Clears cache |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function clear():array |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Execute query |
||
| 49 | * |
||
| 50 | * |
||
| 51 | * @param Request $request |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function exec(Request $request): array |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Use explain for query |
||
| 68 | * |
||
| 69 | * |
||
| 70 | * @param Request $request |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function explain(Request $request): array |
||
| 83 | |||
| 84 | /** |
||
| 85 | * |
||
| 86 | * @return array |
||
| 87 | */ |
||
| 88 | public function serverInfo(): array |
||
| 92 | } |
||
| 93 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.