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 |
||
| 3 | class User extends \Phalcon\Mvc\Model |
||
|
|
|||
| 4 | { |
||
| 5 | |||
| 6 | /** |
||
| 7 | * |
||
| 8 | * @var integer |
||
| 9 | */ |
||
| 10 | protected $id; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $mail; |
||
| 17 | |||
| 18 | protected $image; |
||
| 19 | /** |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $password; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $identite; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * |
||
| 33 | * @var int |
||
| 34 | */ |
||
| 35 | protected $idTypeUser; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Method to set the value of field id |
||
| 39 | * |
||
| 40 | * @param integer $id |
||
| 41 | * @return $this |
||
| 42 | */ |
||
| 43 | public function setId($id) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Method to set the value of field mail |
||
| 52 | * |
||
| 53 | * @param string $mail |
||
| 54 | * @return $this |
||
| 55 | */ |
||
| 56 | public function setMail($mail) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Method to set the value of field password |
||
| 65 | * |
||
| 66 | * @param string $password |
||
| 67 | * @return $this |
||
| 68 | */ |
||
| 69 | public function setPassword($password) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Method to set the value of field identite |
||
| 78 | * |
||
| 79 | * @param string $identite |
||
| 80 | * @return $this |
||
| 81 | */ |
||
| 82 | public function setIdentite($identite) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Method to set the value of field role |
||
| 91 | * |
||
| 92 | * @param string $role |
||
| 93 | * @return $this |
||
| 94 | */ |
||
| 95 | public function setIdTypeUser($idTypeUser) |
||
| 101 | |||
| 102 | public function setImage($image){ |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Returns the value of field id |
||
| 109 | * |
||
| 110 | * @return integer |
||
| 111 | */ |
||
| 112 | public function getId() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Returns the value of field mail |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function getMail() |
||
| 126 | |||
| 127 | public function getImage(){ |
||
| 130 | /** |
||
| 131 | * Returns the value of field password |
||
| 132 | * |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | public function getPassword() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Returns the value of field identite |
||
| 142 | * |
||
| 143 | * @return string |
||
| 144 | */ |
||
| 145 | public function getIdentite() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns the value of field role |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | public function getIdTypeUser() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Initialize method for model. |
||
| 162 | */ |
||
| 163 | View Code Duplication | public function initialize() |
|
| 170 | |||
| 171 | public function toString(){ |
||
| 174 | |||
| 175 | //Return a string containing the principal content of the model |
||
| 176 | public function getPrincipal(){ |
||
| 179 | |||
| 180 | |||
| 181 | /** |
||
| 182 | * Returns table name mapped in the model. |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getSource() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Allows to query a set of records that match the specified conditions |
||
| 193 | * |
||
| 194 | * @param mixed $parameters |
||
| 195 | * @return User[] |
||
| 196 | */ |
||
| 197 | public static function find($parameters = null) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Allows to query the first record that match the specified conditions |
||
| 204 | * |
||
| 205 | * @param mixed $parameters |
||
| 206 | * @return User |
||
| 207 | */ |
||
| 208 | public static function findFirst($parameters = null) |
||
| 212 | |||
| 213 | } |
||
| 214 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.