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 |
||
| 14 | class TagController extends ApiController |
||
| 15 | { |
||
| 16 | protected $tagTranformer; |
||
| 17 | |||
| 18 | function __construct(TagTransformer $tagTransformer) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Display a listing of the resource. |
||
| 28 | * |
||
| 29 | * @return \Illuminate\Http\Response |
||
| 30 | */ |
||
| 31 | public function index($taskId = null) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Show the form for creating a new resource. |
||
| 43 | * |
||
| 44 | * @return \Illuminate\Http\Response |
||
| 45 | */ |
||
| 46 | public function create() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Store a newly created resource in storage. |
||
| 53 | * |
||
| 54 | * @param \Illuminate\Http\Request $request |
||
| 55 | * @return \Illuminate\Http\Response |
||
| 56 | */ |
||
| 57 | public function store() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Display the specified resource. |
||
| 71 | * |
||
| 72 | * @param int $id |
||
| 73 | * @return \Illuminate\Http\Response |
||
| 74 | */ |
||
| 75 | View Code Duplication | public function show($id) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Show the form for editing the specified resource. |
||
| 89 | * |
||
| 90 | * @param int $id |
||
| 91 | * @return \Illuminate\Http\Response |
||
| 92 | */ |
||
| 93 | public function edit($id) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Update the specified resource in storage. |
||
| 100 | * |
||
| 101 | * @param \Illuminate\Http\Request $request |
||
| 102 | * @param int $id |
||
| 103 | * @return \Illuminate\Http\Response |
||
| 104 | */ |
||
| 105 | public function update(Request $request, $id) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Remove the specified resource from storage. |
||
| 120 | * |
||
| 121 | * @param int $id |
||
| 122 | * @return \Illuminate\Http\Response |
||
| 123 | */ |
||
| 124 | public function destroy($id) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param $taskId |
||
| 131 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
||
| 132 | */ |
||
| 133 | public function getTags($taskId) |
||
| 137 | } |
||
| 138 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.