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 |
||
| 8 | abstract class Model implements ModelInterface |
||
| 9 | { |
||
| 10 | |||
| 11 | |||
| 12 | protected $properties = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Store instance of database connection used. |
||
| 16 | * @var [type] |
||
| 17 | */ |
||
| 18 | protected $databaseConnection; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The id of the model. |
||
| 22 | * |
||
| 23 | * @property string $id |
||
| 24 | */ |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Create a model instance. |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
||
| 37 | /** |
||
| 38 | * Sets into $properties the $key => $value pairs |
||
| 39 | * |
||
| 40 | * @param string $key |
||
| 41 | * @param string $val |
||
| 42 | * |
||
| 43 | */ |
||
| 44 | public function __set($key, $val) |
||
| 48 | /** |
||
| 49 | * @param string $key |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function __get($key) |
||
| 57 | /** |
||
| 58 | * Get all the model properties. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | public function getProperties() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Set model properties. |
||
| 69 | * |
||
| 70 | */ |
||
| 71 | public function setProperties(array $properties) |
||
| 75 | /** |
||
| 76 | * Gets the name of the child class with a 's'. |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function getTableName() |
||
| 86 | /** |
||
| 87 | * Find the particular model with the passed id. |
||
| 88 | * |
||
| 89 | * @param int $id |
||
| 90 | * |
||
| 91 | * @return object |
||
| 92 | */ |
||
| 93 | public static function find($id) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Get the particular model with the passed id. |
||
| 101 | * |
||
| 102 | * @param int $id |
||
| 103 | * |
||
| 104 | * @return object |
||
| 105 | */ |
||
| 106 | public function get($id) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Get all the models from the database. |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | */ |
||
| 123 | public static function getAll() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Returns all the models from the database. |
||
| 131 | * |
||
| 132 | * @return array |
||
| 133 | */ |
||
| 134 | public function all() |
||
| 143 | /** |
||
| 144 | * Update the model in the database. |
||
| 145 | * |
||
| 146 | * @return int |
||
| 147 | */ |
||
| 148 | public function update() |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Insert the model values into the database. |
||
| 169 | * |
||
| 170 | * @return int |
||
| 171 | */ |
||
| 172 | public function create() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Save the model data to the database. |
||
| 198 | * |
||
| 199 | * @return boolean |
||
| 200 | */ |
||
| 201 | public function save() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Delete a model from the database. |
||
| 208 | * @param int $id |
||
| 209 | * @return boolean |
||
| 210 | */ |
||
| 211 | public static function destroy($id) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Delete model from the database. |
||
| 219 | * |
||
| 220 | * @param int $id |
||
| 221 | * @return boolean |
||
| 222 | */ |
||
| 223 | public function delete($id) |
||
| 230 | |||
| 231 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.