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 Message extends \Phalcon\Mvc\Model |
||
|
|
|||
| 4 | { |
||
| 5 | |||
| 6 | /** |
||
| 7 | * |
||
| 8 | * @var integer |
||
| 9 | */ |
||
| 10 | protected $id; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $objet; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $content; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $date; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * |
||
| 32 | * @var integer |
||
| 33 | */ |
||
| 34 | protected $idUser; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * |
||
| 38 | * @var integer |
||
| 39 | */ |
||
| 40 | protected $idProjet; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * |
||
| 44 | * @var integer |
||
| 45 | */ |
||
| 46 | protected $idFil; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Method to set the value of field id |
||
| 50 | * |
||
| 51 | * @param integer $id |
||
| 52 | * @return $this |
||
| 53 | */ |
||
| 54 | public function setId($id) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Method to set the value of field objet |
||
| 63 | * |
||
| 64 | * @param string $objet |
||
| 65 | * @return $this |
||
| 66 | */ |
||
| 67 | public function setObjet($objet) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Method to set the value of field content |
||
| 76 | * |
||
| 77 | * @param string $content |
||
| 78 | * @return $this |
||
| 79 | */ |
||
| 80 | public function setContent($content) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Method to set the value of field date |
||
| 89 | * |
||
| 90 | * @param string $date |
||
| 91 | * @return $this |
||
| 92 | */ |
||
| 93 | public function setDate($date) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Method to set the value of field idUser |
||
| 102 | * |
||
| 103 | * @param integer $idUser |
||
| 104 | * @return $this |
||
| 105 | */ |
||
| 106 | public function setIdUser($idUser) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Method to set the value of field idProjet |
||
| 115 | * |
||
| 116 | * @param integer $idProjet |
||
| 117 | * @return $this |
||
| 118 | */ |
||
| 119 | public function setIdProjet($idProjet) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Method to set the value of field idFil |
||
| 128 | * |
||
| 129 | * @param integer $idFil |
||
| 130 | * @return $this |
||
| 131 | */ |
||
| 132 | public function setIdFil($idFil) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Returns the value of field id |
||
| 141 | * |
||
| 142 | * @return integer |
||
| 143 | */ |
||
| 144 | public function getId() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Returns the value of field objet |
||
| 151 | * |
||
| 152 | * @return string |
||
| 153 | */ |
||
| 154 | public function getObjet() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Returns the value of field content |
||
| 161 | * |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getContent() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Returns the value of field date |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function getDate() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Returns the value of field idUser |
||
| 181 | * |
||
| 182 | * @return integer |
||
| 183 | */ |
||
| 184 | public function getIdUser() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Returns the value of field idProjet |
||
| 191 | * |
||
| 192 | * @return integer |
||
| 193 | */ |
||
| 194 | public function getIdProjet() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Returns the value of field idFil |
||
| 201 | * |
||
| 202 | * @return integer |
||
| 203 | */ |
||
| 204 | public function getIdFil() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Initialize method for model. |
||
| 211 | */ |
||
| 212 | View Code Duplication | public function initialize() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * Returns table name mapped in the model. |
||
| 222 | * |
||
| 223 | * @return string |
||
| 224 | */ |
||
| 225 | public function getSource() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Allows to query a set of records that match the specified conditions |
||
| 232 | * |
||
| 233 | * @param mixed $parameters |
||
| 234 | * @return Message[] |
||
| 235 | */ |
||
| 236 | public static function find($parameters = null) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Allows to query the first record that match the specified conditions |
||
| 243 | * |
||
| 244 | * @param mixed $parameters |
||
| 245 | * @return Message |
||
| 246 | */ |
||
| 247 | public static function findFirst($parameters = null) |
||
| 251 | |||
| 252 | public function toString(){ |
||
| 255 | |||
| 256 | } |
||
| 257 |
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.