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 |
||
10 | trait DiscussLogPresenter |
||
11 | { |
||
12 | /** |
||
13 | * Get the type related to the Event. |
||
14 | * |
||
15 | * @return string |
||
|
|||
16 | */ |
||
17 | public function getTypeAttribute() |
||
36 | |||
37 | /** |
||
38 | * Get the old category. |
||
39 | * |
||
40 | * @return \Xetaravel\Models\DiscussCategory |
||
41 | */ |
||
42 | View Code Duplication | public function getOldCategoryAttribute() |
|
50 | |||
51 | /** |
||
52 | * Get the new category. |
||
53 | * |
||
54 | * @return \Xetaravel\Models\DiscussCategory |
||
55 | */ |
||
56 | View Code Duplication | public function getNewCategoryAttribute() |
|
64 | } |
||
65 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.