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 |
||
| 19 | class ApiDepartmentsController extends Controller |
||
| 20 | { |
||
| 21 | private $transformer; |
||
| 22 | private $fractal; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * ApiDepartmentsController constructor. |
||
| 26 | */ |
||
| 27 | public function __construct() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Display a listing of the resource. |
||
| 35 | * |
||
| 36 | * @TODO Needs test |
||
| 37 | * @TODO Needs documentation |
||
| 38 | * @param \Illuminate\Http\Request $request |
||
| 39 | * @return \Illuminate\Http\Response |
||
| 40 | */ |
||
| 41 | public function index(Request $request) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Display the specified resource. |
||
| 66 | * |
||
| 67 | * @TODO needs tests |
||
| 68 | * @TODO needs documentation |
||
| 69 | * @param int $id |
||
| 70 | * @return \Illuminate\Http\Response |
||
| 71 | */ |
||
| 72 | public function show($id) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Store a newly created resource in storage. |
||
| 90 | * |
||
| 91 | * @TODO needs test |
||
| 92 | * @TODO Needs documentation |
||
| 93 | * @param Requests\DepartmentsValidator $input the input bag from the request. |
||
| 94 | * @return \Illuminate\Http\Response |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function store(Requests\DepartmentsValidator $input) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Update the specified resource in storage. |
||
| 110 | * |
||
| 111 | * @TODO Needs documentation |
||
| 112 | * @TODO Needs tests |
||
| 113 | * @param Requests\DepartmentsValidator $input the input bag from the request. |
||
| 114 | * @param \Illuminate\Http\Request $request |
||
| 115 | * @param int $id |
||
| 116 | * @return \Illuminate\Http\Response |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function update(Requests\DepartmentsValidator $input, Request $request, $id) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Remove the specified resource from storage. |
||
| 132 | * |
||
| 133 | * @TODO need tests |
||
| 134 | * #TODO needs documentation |
||
| 135 | * @param int $id |
||
| 136 | * @return \Illuminate\Http\Response |
||
| 137 | */ |
||
| 138 | public function destroy($id) |
||
| 153 | } |
||
| 154 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.