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 |
||
| 10 | class Notification extends Model |
||
| 11 | { |
||
| 12 | protected $fillable = [ |
||
| 13 | 'to_id', |
||
| 14 | 'to_type', |
||
| 15 | 'from_id', |
||
| 16 | 'from_type', |
||
| 17 | 'category_id', |
||
| 18 | 'read', |
||
| 19 | 'url', |
||
| 20 | 'extra', |
||
| 21 | 'expires_at', |
||
| 22 | 'stack_id', |
||
| 23 | ]; |
||
| 24 | |||
| 25 | protected $appends = [ |
||
| 26 | 'text', |
||
| 27 | ]; |
||
| 28 | |||
| 29 | protected $casts = [ |
||
| 30 | 'extra' => 'array', |
||
| 31 | ]; |
||
| 32 | |||
| 33 | public function __construct($attributes = []) |
||
| 43 | |||
| 44 | public function category() |
||
| 48 | |||
| 49 | public function from() |
||
| 57 | |||
| 58 | public function to() |
||
| 66 | |||
| 67 | public function getCustomFillableFields() |
||
| 71 | |||
| 72 | protected function mergeFillables() |
||
| 78 | |||
| 79 | public function getTemplateBodyAttribute() |
||
| 91 | |||
| 92 | public function getTextAttribute() |
||
| 101 | |||
| 102 | public function read() |
||
| 106 | |||
| 107 | public function unread() |
||
| 111 | |||
| 112 | public function resend() |
||
| 119 | |||
| 120 | public function isAnonymous() |
||
| 124 | |||
| 125 | View Code Duplication | public function scopeByCategory(Builder $query, $category) |
|
| 136 | |||
| 137 | public function scopeByRead(Builder $query, $read = 1) |
||
| 141 | } |
||
| 142 |
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@propertyannotation 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.