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 |
||
12 | class User extends Authenticatable |
||
13 | { |
||
14 | use Notifiable; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $table = 'users'; |
||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | public $timestamps = true; |
||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $fillable = ['username', 'emp_num', 'first_name', 'nickname', 'last_name', |
||
28 | 'email', 'phone', 'status', 'clearance', 'elig_date', 'inv', 'inv_close', 'destroyed_date', |
||
29 | 'supervisor_id', 'access_level', 'password', ]; |
||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $hidden = ['username', 'password', 'remember_token']; |
||
34 | |||
35 | /** |
||
36 | * make destroyed_date a Carbon instance. |
||
37 | */ |
||
38 | protected $dates = ['destroyed_date']; |
||
39 | |||
40 | public function supervisor() |
||
41 | { |
||
42 | return $this->belongsTo('SET\User', 'supervisor_id'); |
||
43 | } |
||
44 | |||
45 | public function subordinates() |
||
46 | { |
||
47 | return $this->hasMany('SET\User', 'supervisor_id'); |
||
48 | } |
||
49 | |||
50 | public function attachments() |
||
51 | { |
||
52 | return $this->morphMany('SET\Attachment', 'imageable'); |
||
53 | } |
||
54 | |||
55 | public function notes() |
||
56 | { |
||
57 | return $this->hasMany('SET\Note'); |
||
58 | } |
||
59 | |||
60 | public function travels() |
||
61 | { |
||
62 | return $this->hasMany('SET\Travel'); |
||
63 | } |
||
64 | |||
65 | public function visits() |
||
66 | { |
||
67 | return $this->hasMany('SET\Visit'); |
||
68 | } |
||
69 | |||
70 | public function assignedTrainings() |
||
71 | { |
||
72 | return $this->hasMany('SET\TrainingUser', 'user_id'); |
||
73 | } |
||
74 | |||
75 | public function trainingUsers() |
||
76 | { |
||
77 | return $this->hasMany('SET\TrainingUser', 'user_id'); |
||
78 | } |
||
79 | |||
80 | public function logs() |
||
81 | { |
||
82 | return $this->hasMany('SET\Log'); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
87 | */ |
||
88 | public function trainings() |
||
92 | |||
93 | /** |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
95 | */ |
||
96 | public function groups() |
||
100 | |||
101 | /** |
||
102 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
103 | */ |
||
104 | public function duties() |
||
108 | |||
109 | public function dutySwap() |
||
113 | |||
114 | public function news() |
||
118 | |||
119 | /** |
||
120 | * If we have a nickname, return 'lastname, nickname' otherwise return 'lastname, firstname'. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getUserFullNameAttribute() |
||
125 | { |
||
126 | if ($this->attributes['id'] == 1) { |
||
127 | return 'system'; |
||
142 | |||
143 | /** |
||
144 | * @param $query |
||
145 | * @param $input |
||
146 | */ |
||
147 | public function scopeSearchUsers($query, $input) |
||
153 | |||
154 | /** |
||
155 | * @param $query |
||
156 | * |
||
157 | * @return mixed |
||
158 | */ |
||
159 | public function scopeActive($query) |
||
163 | |||
164 | public function scopeSkipSystem($query) |
||
168 | |||
169 | /** |
||
170 | * @param string $key |
||
171 | * @param mixed $value |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | View Code Duplication | public function setAttribute($key, $value) |
|
183 | |||
184 | public function getDestroyDate($status) |
||
196 | } |
||
197 |