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 |
||
| 19 | View Code Duplication | class CSurveyQuestionOption |
|
|
|
|||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var integer |
||
| 23 | * |
||
| 24 | * @ORM\Column(name="iid", type="integer") |
||
| 25 | * @ORM\Id |
||
| 26 | * @ORM\GeneratedValue |
||
| 27 | */ |
||
| 28 | private $iid; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var integer |
||
| 32 | * |
||
| 33 | * @ORM\Column(name="c_id", type="integer") |
||
| 34 | */ |
||
| 35 | private $cId; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var integer |
||
| 39 | * |
||
| 40 | * @ORM\Column(name="question_option_id", type="integer") |
||
| 41 | */ |
||
| 42 | private $questionOptionId; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var integer |
||
| 46 | * |
||
| 47 | * @ORM\Column(name="question_id", type="integer", nullable=false) |
||
| 48 | */ |
||
| 49 | private $questionId; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var integer |
||
| 53 | * |
||
| 54 | * @ORM\Column(name="survey_id", type="integer", nullable=false) |
||
| 55 | */ |
||
| 56 | private $surveyId; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | * |
||
| 61 | * @ORM\Column(name="option_text", type="text", nullable=false) |
||
| 62 | */ |
||
| 63 | private $optionText; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var integer |
||
| 67 | * |
||
| 68 | * @ORM\Column(name="sort", type="integer", nullable=false) |
||
| 69 | */ |
||
| 70 | private $sort; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var integer |
||
| 74 | * |
||
| 75 | * @ORM\Column(name="value", type="integer", nullable=false) |
||
| 76 | */ |
||
| 77 | private $value; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Set questionId |
||
| 81 | * |
||
| 82 | * @param integer $questionId |
||
| 83 | * @return CSurveyQuestionOption |
||
| 84 | */ |
||
| 85 | public function setQuestionId($questionId) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get questionId |
||
| 94 | * |
||
| 95 | * @return integer |
||
| 96 | */ |
||
| 97 | public function getQuestionId() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Set surveyId |
||
| 104 | * |
||
| 105 | * @param integer $surveyId |
||
| 106 | * @return CSurveyQuestionOption |
||
| 107 | */ |
||
| 108 | public function setSurveyId($surveyId) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get surveyId |
||
| 117 | * |
||
| 118 | * @return integer |
||
| 119 | */ |
||
| 120 | public function getSurveyId() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Set optionText |
||
| 127 | * |
||
| 128 | * @param string $optionText |
||
| 129 | * @return CSurveyQuestionOption |
||
| 130 | */ |
||
| 131 | public function setOptionText($optionText) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Get optionText |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getOptionText() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Set sort |
||
| 150 | * |
||
| 151 | * @param integer $sort |
||
| 152 | * @return CSurveyQuestionOption |
||
| 153 | */ |
||
| 154 | public function setSort($sort) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Get sort |
||
| 163 | * |
||
| 164 | * @return integer |
||
| 165 | */ |
||
| 166 | public function getSort() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Set value |
||
| 173 | * |
||
| 174 | * @param integer $value |
||
| 175 | * @return CSurveyQuestionOption |
||
| 176 | */ |
||
| 177 | public function setValue($value) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Get value |
||
| 186 | * |
||
| 187 | * @return integer |
||
| 188 | */ |
||
| 189 | public function getValue() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Set questionOptionId |
||
| 196 | * |
||
| 197 | * @param integer $questionOptionId |
||
| 198 | * @return CSurveyQuestionOption |
||
| 199 | */ |
||
| 200 | public function setQuestionOptionId($questionOptionId) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get questionOptionId |
||
| 209 | * |
||
| 210 | * @return integer |
||
| 211 | */ |
||
| 212 | public function getQuestionOptionId() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Set cId |
||
| 219 | * |
||
| 220 | * @param integer $cId |
||
| 221 | * @return CSurveyQuestionOption |
||
| 222 | */ |
||
| 223 | public function setCId($cId) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Get cId |
||
| 232 | * |
||
| 233 | * @return integer |
||
| 234 | */ |
||
| 235 | public function getCId() |
||
| 239 | } |
||
| 240 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.