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 |
||
| 13 | class ConversationController extends Controller |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Show the conversation by its id. |
||
| 17 | * |
||
| 18 | * @return \Illuminate\Http\Response |
||
|
|
|||
| 19 | */ |
||
| 20 | public function show(Request $request, string $slug, int $id) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Show the create form. |
||
| 46 | * |
||
| 47 | * @return \Illuminate\View\View |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function showCreateForm(): View |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Handle a conversation create request for the application. |
||
| 60 | * |
||
| 61 | * @param \Illuminate\Http\Request $request |
||
| 62 | * |
||
| 63 | * @return \Illuminate\Http\RedirectResponse |
||
| 64 | */ |
||
| 65 | public function create(Request $request) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Handle a conversation update request for the application. |
||
| 90 | * |
||
| 91 | * @param \Illuminate\Http\Request $request |
||
| 92 | * @param string $slug |
||
| 93 | * @param int $id |
||
| 94 | * |
||
| 95 | * @return \Illuminate\Http\RedirectResponse |
||
| 96 | */ |
||
| 97 | public function update(Request $request, string $slug, int $id) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Get the current page for the conversation. |
||
| 111 | * |
||
| 112 | * @param \Illuminate\Http\Request $request |
||
| 113 | * |
||
| 114 | * @return int |
||
| 115 | */ |
||
| 116 | protected function getCurrentPage(Request $request): int |
||
| 120 | } |
||
| 121 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.