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 |
||
15 | abstract class User extends BaseModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract |
||
16 | { |
||
17 | use Authenticatable, Authorizable, CanResetPassword, HasRoles, SoftDeletes; |
||
18 | |||
19 | /** |
||
20 | * Define the SQL table for this model |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $table = 'users'; |
||
25 | |||
26 | /** |
||
27 | * The attributes excluded from the model's JSON form. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $hidden = [ |
||
32 | 'password', |
||
33 | 'remember_token', |
||
34 | ]; |
||
35 | |||
36 | protected $fillable = [ |
||
37 | 'username', |
||
38 | 'password', |
||
39 | 'email', |
||
40 | 'first_name', |
||
41 | 'last_name', |
||
42 | 'display_name', |
||
43 | 'timezone', |
||
44 | 'location', |
||
45 | 'url', |
||
46 | 'social_id', |
||
47 | 'social_avatar', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Tell eloquent to set deleted_at as a carbon date. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $dates = [ |
||
56 | 'deleted_at', |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * Determines if the users has global rights. |
||
61 | * |
||
62 | * @return mixed |
||
63 | */ |
||
64 | View Code Duplication | public function isSuperUser() |
|
74 | |||
75 | /** |
||
76 | * Grant a user global rights. |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | View Code Duplication | public function makeSuperUser() |
|
91 | |||
92 | /** |
||
93 | * Order by name ascending scope |
||
94 | * |
||
95 | * @param Builder $query The current query to append to |
||
96 | * |
||
97 | * @return Builder |
||
98 | */ |
||
99 | public function scopeOrderByNameAsc($query) |
||
103 | |||
104 | /** |
||
105 | * Make sure to hash the user's password on save |
||
106 | * |
||
107 | * @param string $value The value of the attribute (Auto Set) |
||
108 | */ |
||
109 | public function setPasswordAttribute($value) |
||
113 | } |
||
114 |