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 |
||
| 8 | class DiscussThreadRepository |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Create the new thread and save it. |
||
| 13 | * |
||
| 14 | * @param array $data The data used to create the thread. |
||
| 15 | * |
||
| 16 | * @return \Xetaravel\Models\DiscussThread |
||
| 17 | */ |
||
| 18 | public static function create(array $data): DiscussThread |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Update the article data and save it. |
||
| 40 | * |
||
| 41 | * @param array $data The data used to update the article. |
||
| 42 | * @param \Xetaravel\Models\Article $article The article to update. |
||
|
|
|||
| 43 | * |
||
| 44 | * @return \Xetaravel\Models\Article |
||
| 45 | */ |
||
| 46 | View Code Duplication | public static function update(array $data, Article $article): Article |
|
| 56 | } |
||
| 57 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.