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 |
||
19 | class Forum extends AbstractModel |
||
20 | { |
||
21 | public $table = 'forums'; |
||
22 | |||
23 | public $fillable = ['name', 'description', 'category_id', 'public']; |
||
24 | |||
25 | /** |
||
26 | * Eloquent Relation. |
||
27 | * @return mixed |
||
28 | */ |
||
29 | public function category() |
||
33 | |||
34 | /** |
||
35 | * Eloquent Relation. |
||
36 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
37 | */ |
||
38 | public function posts() |
||
42 | |||
43 | /** |
||
44 | * Get the number of threads inside the current forum. |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function getThreadCount() |
||
56 | |||
57 | /** |
||
58 | * Is model data valid. |
||
59 | * |
||
60 | * @param array|object $data The data to validate. |
||
61 | * |
||
62 | * @return boolean |
||
63 | */ |
||
64 | View Code Duplication | public static function valid($data) |
|
78 | } |
||
79 |