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 |
||
12 | class Model extends \Illuminate\Database\Eloquent\Model |
||
13 | { |
||
14 | /** |
||
15 | * Get the format for database stored dates. |
||
16 | * |
||
17 | * @return string |
||
18 | */ |
||
19 | public function getDateFormat() |
||
23 | |||
24 | /** |
||
25 | * Get the table qualified key name. |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | public function getQualifiedKeyName() |
||
33 | |||
34 | /** |
||
35 | * Ensure Timestamps are returned in DateTime. |
||
36 | * |
||
37 | * @param \DateTime $value |
||
38 | * |
||
39 | * @return \DateTime |
||
40 | */ |
||
41 | protected function asDateTime($value) |
||
50 | |||
51 | /** |
||
52 | * Retain DateTime format for storage. |
||
53 | * |
||
54 | * @param \DateTime $value |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function fromDateTime($value) |
||
66 | |||
67 | /** |
||
68 | * Get a new query builder instance for the connection. |
||
69 | * |
||
70 | * @return Builder |
||
71 | */ |
||
72 | protected function newBaseQueryBuilder() |
||
82 | |||
83 | /** |
||
84 | * Create a new Eloquent query builder for the model. |
||
85 | * |
||
86 | * @param \duxet\Rethinkdb\Query\Builder $query |
||
87 | * |
||
88 | * @return \duxet\Rethinkdb\Eloquent\Builder|static |
||
89 | */ |
||
90 | public function newEloquentBuilder($query) |
||
94 | |||
95 | /** |
||
96 | * Define an inverse one-to-one or many relationship. |
||
97 | * |
||
98 | * @param string $related |
||
99 | * @param string $foreignKey |
||
100 | * @param string $otherKey |
||
101 | * @param string $relation |
||
102 | * |
||
103 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
104 | */ |
||
105 | public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) |
||
129 | |||
130 | /** |
||
131 | * Define a one-to-one relationship. |
||
132 | * |
||
133 | * @param string $related |
||
134 | * @param string $foreignKey |
||
135 | * @param string $localKey |
||
136 | * |
||
137 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
138 | */ |
||
139 | View Code Duplication | public function hasOne($related, $foreignKey = null, $localKey = null) |
|
147 | |||
148 | /** |
||
149 | * Define a one-to-many relationship. |
||
150 | * |
||
151 | * @param string $related |
||
152 | * @param string $foreignKey |
||
153 | * @param string $localKey |
||
154 | * |
||
155 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
156 | */ |
||
157 | View Code Duplication | public function hasMany($related, $foreignKey = null, $localKey = null) |
|
165 | |||
166 | /** |
||
167 | * Determine if the new and old values for a given key are numerically equivalent. |
||
168 | * |
||
169 | * @param string $key |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | protected function originalIsNumericallyEquivalent($key) |
||
187 | } |
||
188 |
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.