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 | ]; |
||
47 | |||
48 | /** |
||
49 | * Tell eloquent to set deleted_at as a carbon date. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $dates = [ |
||
54 | 'deleted_at', |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * Determines if the users has global rights. |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | View Code Duplication | public function isSuperUser() |
|
72 | |||
73 | /** |
||
74 | * Grant a user global rights. |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | View Code Duplication | public function makeSuperUser() |
|
89 | |||
90 | /** |
||
91 | * Order by name ascending scope |
||
92 | * |
||
93 | * @param Builder $query The current query to append to |
||
94 | * |
||
95 | * @return Builder |
||
96 | */ |
||
97 | public function scopeOrderByNameAsc($query) |
||
101 | |||
102 | /** |
||
103 | * Make sure to hash the user's password on save |
||
104 | * |
||
105 | * @param string $value The value of the attribute (Auto Set) |
||
106 | */ |
||
107 | public function setPasswordAttribute($value) |
||
111 | } |
||
112 |