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 |
||
18 | class Discount extends Model implements DiscountContract |
||
19 | { |
||
20 | use SoftDeletes; |
||
21 | |||
22 | protected $guarded = ['id', 'orderAmountLimit']; |
||
23 | |||
24 | protected $appends = ['use_start_time', 'use_end_time', 'action_type']; |
||
25 | |||
26 | /** |
||
27 | * Address constructor. |
||
28 | * |
||
29 | * @param array $attributes |
||
30 | */ |
||
31 | 14 | public function __construct(array $attributes = []) |
|
37 | |||
38 | 14 | public function rules() |
|
42 | |||
43 | 14 | public function actions() |
|
47 | |||
48 | /** |
||
49 | * @return mixed |
||
50 | */ |
||
51 | 4 | public function hasRules() |
|
55 | |||
56 | 1 | public function isCouponBased() |
|
60 | |||
61 | 3 | public function getActions() |
|
65 | |||
66 | 4 | public function getRules() |
|
70 | |||
71 | 1 | public function setCouponUsed() |
|
74 | |||
75 | 2 | public function getUsestartAtAttribute($value) |
|
83 | |||
84 | 2 | public function getUseendAtAttribute($value) |
|
92 | |||
93 | 4 | public function getStartsAt() |
|
97 | |||
98 | 4 | public function getEndsAt() |
|
102 | |||
103 | /** |
||
104 | * @return mixed |
||
105 | */ |
||
106 | 4 | public function getUsed() |
|
110 | |||
111 | /** |
||
112 | * @return mixed |
||
113 | */ |
||
114 | 4 | public function getUsageLimit() |
|
118 | |||
119 | View Code Duplication | public function getUseStartTimeAttribute() |
|
129 | |||
130 | View Code Duplication | public function getUseEndTimeAttribute() |
|
140 | |||
141 | /** |
||
142 | * 为方便前台展示优惠券信息. |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | public function getActionTypeAttribute() |
||
164 | } |
||
165 |
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.