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 |
||
11 | class User extends Model implements AuthenticatableContract, CanResetPasswordContract |
||
12 | { |
||
13 | use Authenticatable, |
||
14 | CanResetPassword; |
||
15 | |||
16 | /** |
||
17 | * The database table used by the model. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $table = 'users'; |
||
22 | |||
23 | /** |
||
24 | * The attributes that are mass assignable. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $fillable = ['user_name', 'email', 'password', 'active', 'first_name', 'last_name', 'ban', 'ext', 'mobile', 'profile_pic', |
||
29 | 'phone_number', 'company', 'agent_sign', 'account_type', 'account_status', |
||
30 | 'assign_group', 'primary_dpt', 'agent_tzone', 'daylight_save', 'limit_access', |
||
31 | 'directory_listing', 'vacation_mode', 'role', 'internal_note', 'country_code', 'not_accept_ticket', 'is_delete', ]; |
||
32 | |||
33 | /** |
||
34 | * The attributes excluded from the model's JSON form. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $hidden = ['password', 'remember_token']; |
||
39 | |||
40 | public function getProfilePicAttribute($value) |
||
56 | |||
57 | public function avatar() |
||
64 | |||
65 | public function getOrganizationRelation() |
||
78 | |||
79 | View Code Duplication | public function getOrganization() |
|
91 | |||
92 | View Code Duplication | public function getOrgWithLink() |
|
106 | |||
107 | public function getEmailAttribute($value) |
||
115 | |||
116 | public function getExtraInfo($id = '') |
||
126 | |||
127 | View Code Duplication | public function checkArray($key, $array) |
|
138 | |||
139 | public function twitterLink() |
||
150 | |||
151 | public function name() |
||
166 | |||
167 | public function getFullNameAttribute() |
||
171 | |||
172 | // public function save() { |
||
173 | // dd($this->id); |
||
174 | // parent::save(); |
||
175 | // } |
||
176 | |||
177 | // public function save(array $options = array()) { |
||
178 | // parent::save($options); |
||
179 | // dd($this->where('id',$this->id)->select('first_name','last_name','user_name','email')->get()->toJson()); |
||
180 | // } |
||
181 | } |
||
182 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: