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 |
||
| 9 | class SensorDataController extends Controller |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Create a new controller instance. |
||
| 13 | * |
||
| 14 | * @return void |
||
|
|
|||
| 15 | */ |
||
| 16 | public function __construct() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Display a listing of the resource. |
||
| 23 | * |
||
| 24 | * @param SensorDataDataTable $dataTable |
||
| 25 | * @return Response |
||
| 26 | */ |
||
| 27 | public function index(SensorDataDataTable $dataTable) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Show the form for creating a new resource. |
||
| 34 | * |
||
| 35 | * @return Response |
||
| 36 | */ |
||
| 37 | public function create() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Store a newly created resource in storage. |
||
| 44 | * |
||
| 45 | * @return Response |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function store() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Display the specified resource. |
||
| 62 | * |
||
| 63 | * @param Request $request |
||
| 64 | * @param int $id |
||
| 65 | * @return Response |
||
| 66 | */ |
||
| 67 | public function show(Request $request, $id) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Show the form for editing the specified resource. |
||
| 76 | * |
||
| 77 | * @param int $id |
||
| 78 | * @return Response |
||
| 79 | */ |
||
| 80 | public function edit(Request $request, $id) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Update the specified resource in storage. |
||
| 89 | * |
||
| 90 | * @param int $id |
||
| 91 | * @return Response |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function update($id) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Remove the specified resource from storage. |
||
| 106 | * |
||
| 107 | * @param int $id |
||
| 108 | * @return Response |
||
| 109 | */ |
||
| 110 | public function destroy($id) |
||
| 116 | |||
| 117 | } |
||
| 118 |
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.