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 |
||
26 | class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract |
||
27 | { |
||
28 | use Authenticatable, CanResetPassword, SoftDeletes, UuidForPrimary, |
||
29 | ActionLogTrait, EntityLockTrait, LoginAsPossibility; |
||
30 | |||
31 | /** |
||
32 | * The database table used by the model. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $table = 'users'; |
||
37 | |||
38 | /** |
||
39 | * The attributes that are mass assignable. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $fillable = [ |
||
44 | 'email', |
||
45 | 'password', |
||
46 | 'firstname', |
||
47 | 'avatar', |
||
48 | 'lastname', |
||
49 | 'role_id', |
||
50 | 'is_developer', |
||
51 | 'country_id', |
||
52 | 'mobile_number', |
||
53 | 'gender', |
||
54 | 'birth_date', |
||
55 | 'address', |
||
56 | 'activate_token', |
||
57 | 'status', |
||
58 | ]; |
||
59 | |||
60 | protected $dates = ['deleted_at', 'birth_date']; |
||
61 | |||
62 | /** |
||
63 | * The attributes excluded from the model's JSON form. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $hidden = ['password', 'remember_token']; |
||
68 | |||
69 | public $incrementing = false; |
||
70 | |||
71 | protected $keyType = 'string'; |
||
72 | |||
73 | protected $searchableFields = ['email', 'firstname', 'lastname']; |
||
74 | |||
75 | protected $filterableFields = ['status' => '=']; |
||
76 | |||
77 | protected $sortableFields = ['email', 'firstname', 'lastname', 'status', 'created_at', 'updated_at']; |
||
78 | |||
79 | public function isDeveloper() |
||
83 | |||
84 | public function getAvatar() |
||
99 | |||
100 | public function getFullname() |
||
104 | |||
105 | public function canLogin() |
||
109 | |||
110 | public function role() |
||
118 | |||
119 | public function permissions() |
||
135 | |||
136 | View Code Duplication | public function hasRole($name, $requireAll = false) |
|
155 | |||
156 | View Code Duplication | public function can($permission, $requireAll = false) |
|
184 | |||
185 | public function toArray() |
||
199 | |||
200 | public function country() |
||
204 | |||
205 | public function accessLog() |
||
209 | |||
210 | } |
||
211 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.