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 |
||
9 | class CDatabaseModel implements \Anax\DI\IInjectionAware |
||
10 | { |
||
11 | use \Anax\DI\TInjectable; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * Get the table name. |
||
16 | * |
||
17 | * @return string with the table name. |
||
18 | */ |
||
19 | 2 | public function getSource() |
|
23 | |||
24 | /** |
||
25 | * Find and return specific. |
||
26 | * |
||
27 | * @return this |
||
28 | */ |
||
29 | public function find($id) |
||
38 | |||
39 | |||
40 | /** |
||
41 | * Find and return all. |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | public function findAll() |
||
54 | |||
55 | /** |
||
56 | * Find and return rows based on condition. |
||
57 | * |
||
58 | * @param string $column as key for condition |
||
59 | * @param string $value as value for condition. |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | View Code Duplication | public function findWhere($column, $value) { |
|
72 | |||
73 | /** |
||
74 | * Find and return rows in specific order. |
||
75 | * |
||
76 | * @param string $column as key for condition |
||
77 | * @param string $order as order to sort in, ASC or DESC. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | View Code Duplication | public function findAllOrder($column, $order) { |
|
90 | |||
91 | /** |
||
92 | * Get object properties. |
||
93 | * |
||
94 | * @return array with object properties. |
||
95 | */ |
||
96 | public function getProperties() |
||
104 | |||
105 | /** |
||
106 | * Set object properties. |
||
107 | * |
||
108 | * @param array $properties with properties to set. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function setProperties($properties) |
||
121 | |||
122 | /** |
||
123 | * Save current object/row. |
||
124 | * |
||
125 | * @param array $values key/values to save or empty to use object properties. |
||
126 | * |
||
127 | * @return boolean true or false if saving went okey. |
||
128 | */ |
||
129 | public function save($values = []) |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Create new row. |
||
144 | * |
||
145 | * @param array $values key/values to save. |
||
146 | * |
||
147 | * @return boolean true or false if saving went okey. |
||
148 | */ |
||
149 | public function create($values) |
||
165 | |||
166 | /** |
||
167 | * Update row. |
||
168 | * |
||
169 | * @param array $values key/values to save. |
||
170 | * |
||
171 | * @return boolean true or false if saving went okey. |
||
172 | */ |
||
173 | public function update($values) |
||
192 | |||
193 | /** |
||
194 | * Delete row by id. |
||
195 | * |
||
196 | * @param integer $id to delete. |
||
197 | * |
||
198 | * @return boolean true or false if deleting went okey. |
||
199 | */ |
||
200 | public function delete($id) |
||
209 | |||
210 | /** |
||
211 | * Delete all rows with where condition. |
||
212 | * |
||
213 | * @param string $column as key for condition |
||
214 | * @param string $value as value for condition. |
||
215 | * |
||
216 | * @return boolean true or false if deleting went okey. |
||
217 | */ |
||
218 | public function deleteWhere($column, $value) |
||
227 | |||
228 | /** |
||
229 | * Delete all rows. |
||
230 | * |
||
231 | * @return boolean true or false if deleting went okey. |
||
232 | */ |
||
233 | public function deleteAll() |
||
241 | |||
242 | |||
243 | /** |
||
244 | * Build a select-query. |
||
245 | * |
||
246 | * @param string $columns which columns to select. |
||
247 | * |
||
248 | * @return $this |
||
249 | */ |
||
250 | public function query($columns = '*') |
||
257 | |||
258 | /** |
||
259 | * Build the where part. |
||
260 | * |
||
261 | * @param string $condition for building the where part of the query. |
||
262 | * |
||
263 | * @return $this |
||
264 | */ |
||
265 | public function where($condition) |
||
271 | |||
272 | /** |
||
273 | * Build the where part. |
||
274 | * |
||
275 | * @param string $condition for building the where part of the query. |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function andWhere($condition) |
||
285 | |||
286 | /** |
||
287 | * Execute the query built. |
||
288 | * |
||
289 | * @param array $params for custom query. |
||
290 | * |
||
291 | * @return $this |
||
292 | */ |
||
293 | public function execute($params = []) |
||
300 | |||
301 | /** |
||
302 | * Create a slug of a string, to be used as url. |
||
303 | * |
||
304 | * @param string $str the string to format as slug. |
||
305 | * @returns str the formatted slug. |
||
306 | */ |
||
307 | function slugify($str) { |
||
314 | |||
315 | } |
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.