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 | 63 | public function user() |
|
| 27 | |||
| 28 | 1 | public function author() |
|
| 29 | { |
||
| 30 | 1 | return $this->belongsTo('SET\User', 'author_id'); |
|
| 31 | } |
||
| 32 | |||
| 33 | 16 | public function training() |
|
| 37 | |||
| 38 | 3 | 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 | 62 | public function scopeActiveUsers($query) |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $key |
||
| 60 | * @param mixed $value |
||
| 61 | * |
||
| 62 | * @return $this |
||
| 63 | */ |
||
| 64 | 15 | View Code Duplication | public function setAttribute($key, $value) |
| 72 | |||
| 73 | /** |
||
| 74 | * @param $query |
||
| 75 | * @param $input |
||
| 76 | */ |
||
| 77 | public function scopeRenewTrainings($query) |
||
| 83 | } |
||
| 84 |