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 |
||
| 12 | class PostController extends Controller |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Instantiate a new controller instance. |
||
| 16 | * |
||
| 17 | * @return void |
||
|
|
|||
| 18 | */ |
||
| 19 | public function __construct() |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Display a listing of the resource. |
||
| 26 | * |
||
| 27 | * @return \Illuminate\Http\Response |
||
| 28 | */ |
||
| 29 | public function index() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Show the form for creating a new resource. |
||
| 40 | * |
||
| 41 | * @return \Illuminate\Http\Response |
||
| 42 | */ |
||
| 43 | public function create() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Store a newly created resource in storage. |
||
| 50 | * |
||
| 51 | * @param \App\Http\Requests\ValidatePostRequest $request |
||
| 52 | * @return \Illuminate\Http\Response |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function store(ValidatePostRequest $request) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Display the specified resource. |
||
| 74 | * |
||
| 75 | * @param \Chriscreates\Blog\Post $post |
||
| 76 | * @return \Illuminate\Http\Response |
||
| 77 | */ |
||
| 78 | public function show(Post $post) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Show the form for editing the specified resource. |
||
| 95 | * |
||
| 96 | * @param \Chriscreates\Blog\Post $post |
||
| 97 | * @return \Illuminate\Http\Response |
||
| 98 | */ |
||
| 99 | public function edit(Post $post) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Update the specified resource in storage. |
||
| 106 | * |
||
| 107 | * @param \App\Http\Requests\ValidatePostRequest $request |
||
| 108 | * @param \Chriscreates\Blog\Post $post |
||
| 109 | * @return \Illuminate\Http\Response |
||
| 110 | */ |
||
| 111 | View Code Duplication | public function update(ValidatePostRequest $request, Post $post) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Remove the specified resource from storage. |
||
| 131 | * |
||
| 132 | * @param \Chriscreates\Blog\Post $post |
||
| 133 | * @return \Illuminate\Http\Response |
||
| 134 | */ |
||
| 135 | public function destroy(Post $post) |
||
| 143 | } |
||
| 144 |
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.