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 |
||
| 18 | class ForumReply extends AbstractModel |
||
| 19 | { |
||
| 20 | protected $table = 'forum_post_replies'; |
||
| 21 | |||
| 22 | protected $hidden = []; |
||
| 23 | protected $fillable = ['body', 'post_id', 'author_id']; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Eloquent Relation. |
||
| 27 | * @return mixed |
||
| 28 | */ |
||
| 29 | public function author() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Validates model data. |
||
| 38 | * @param array $data The data to validate. |
||
| 39 | * |
||
| 40 | * @return boolean |
||
| 41 | */ |
||
| 42 | View Code Duplication | public static function valid($data) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Gets the number of replies from the database. |
||
| 59 | * @return mixed |
||
| 60 | */ |
||
| 61 | public static function getReplyCount() |
||
| 66 | } |
||
| 67 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.