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 |
||
7 | class TrainingUser extends Model |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $table = 'training_user'; |
||
13 | /** |
||
14 | * @var bool |
||
15 | */ |
||
16 | public $timestamps = true; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $fillable = ['training_id', 'due_date', 'completed_date', 'comment', 'author_id', 'user_id', 'stop_renewal']; |
||
22 | |||
23 | public function user() |
||
27 | |||
28 | public function author() |
||
32 | |||
33 | public function training() |
||
37 | |||
38 | public function attachments() |
||
42 | |||
43 | /** |
||
44 | * Allows you to call activeUsers() on notes |
||
45 | * to return only notes with active users. |
||
46 | * |
||
47 | * @param $query |
||
48 | * |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function scopeActiveUsers($query) |
||
57 | |||
58 | /** |
||
59 | * @param string $key |
||
60 | * @param mixed $value |
||
61 | * |
||
62 | * @return $this |
||
63 | */ |
||
64 | View Code Duplication | public function setAttribute($key, $value) |
|
72 | |||
73 | /** |
||
74 | * @param $query |
||
75 | * @param $input |
||
76 | */ |
||
77 | public function scopeRenewableTrainings($query) |
||
83 | } |
||
84 |