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 |
||
24 | class Model extends DatabaseQuery implements ModelInterface |
||
25 | { |
||
26 | //Inject the inflector trait |
||
27 | use Inflector; |
||
28 | |||
29 | protected $ouput; |
||
30 | |||
31 | /** |
||
32 | * stripclassName() |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public static function stripclassName() |
||
43 | |||
44 | /** |
||
45 | * Get the table name if defined in the model |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function tableName() |
||
59 | |||
60 | /** |
||
61 | * Get the fields to be fillables defined in the model |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public function fields() |
||
79 | |||
80 | /** |
||
81 | * getClassName() |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getClassName() |
||
95 | |||
96 | /** |
||
97 | * getTableName() |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getTableName($connection) |
||
105 | |||
106 | /** |
||
107 | * getALL() |
||
108 | * Get all record from the database |
||
109 | * |
||
110 | * @return object |
||
111 | */ |
||
112 | public function getAll($dbConnection = NULL) |
||
125 | |||
126 | /** |
||
127 | * where($data, $condition) |
||
128 | * Get data from database where $data = $condition |
||
129 | * |
||
130 | * @return object |
||
131 | */ |
||
132 | public function where($data, $condition = NULL, $dbConnection = NULL) |
||
146 | |||
147 | /** |
||
148 | * find($value) |
||
149 | * Find data from database where id = $value |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | public static function find($value, $dbConnection = NULL) |
||
169 | |||
170 | /** |
||
171 | * save() |
||
172 | * Insert data into database |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | View Code Duplication | public function save($dbConnection = NULL) |
|
189 | |||
190 | /** |
||
191 | * update() |
||
192 | * Update details in database after ::find(2) |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | View Code Duplication | public function update($dbConnection = NULL) |
|
208 | |||
209 | /** |
||
210 | * destroy($value) |
||
211 | * Delete data from database |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | public function destroy($value, $dbConnection = NULL) |
||
228 | } |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.