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 ThreadController extends Controller |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Show the thread by its id. |
||
| 18 | * |
||
| 19 | * @return \Illuminate\Http\Response |
||
|
|
|||
| 20 | */ |
||
| 21 | public function show(Request $request, string $slug, int $id) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Show the create form. |
||
| 43 | * |
||
| 44 | * @return \Illuminate\View\View |
||
| 45 | */ |
||
| 46 | View Code Duplication | public function showCreateForm(): View |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Handle a thread create request for the application. |
||
| 57 | * |
||
| 58 | * @param \Illuminate\Http\Request $request |
||
| 59 | * |
||
| 60 | * @return \Illuminate\Http\RedirectResponse |
||
| 61 | */ |
||
| 62 | public function create(Request $request) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get the current page for the thread. |
||
| 86 | * |
||
| 87 | * @param \Illuminate\Http\Request $request |
||
| 88 | * |
||
| 89 | * @return int |
||
| 90 | */ |
||
| 91 | protected function getCurrentPage(Request $request) |
||
| 95 | } |
||
| 96 |
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.