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 |
||
| 21 | class Skill |
||
| 22 | { |
||
| 23 | const STATUS_DISABLED = 0; |
||
| 24 | const STATUS_ENABLED = 1; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | * |
||
| 29 | * @ORM\Column(name="name", type="string", length=255, nullable=false) |
||
| 30 | */ |
||
| 31 | private $name; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | * |
||
| 36 | * @ORM\Column(name="short_code", type="string", length=100, nullable=false) |
||
| 37 | */ |
||
| 38 | private $shortCode; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | * |
||
| 43 | * @ORM\Column(name="description", type="text", nullable=false) |
||
| 44 | */ |
||
| 45 | private $description; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var integer |
||
| 49 | * |
||
| 50 | * @ORM\Column(name="access_url_id", type="integer", nullable=false) |
||
| 51 | */ |
||
| 52 | private $accessUrlId; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | * |
||
| 57 | * @ORM\Column(name="icon", type="string", length=255, nullable=false) |
||
| 58 | */ |
||
| 59 | private $icon; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | * |
||
| 64 | * @ORM\Column(name="criteria", type="text", nullable=true) |
||
| 65 | */ |
||
| 66 | private $criteria; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var integer |
||
| 70 | * |
||
| 71 | * @ORM\Column(name="status", type="integer", nullable=false, options={"default": 1}) |
||
| 72 | */ |
||
| 73 | private $status; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var \DateTime |
||
| 77 | * |
||
| 78 | * @ORM\Column(name="updated_at", type="datetime", nullable=false) |
||
| 79 | */ |
||
| 80 | private $updatedAt; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var integer |
||
| 84 | * |
||
| 85 | * @ORM\Column(name="id", type="integer") |
||
| 86 | * @ORM\Id |
||
| 87 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 88 | */ |
||
| 89 | private $id; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Profile", inversedBy="skills") |
||
| 93 | * @ORM\JoinColumn(name="profile_id", referencedColumnName="id") |
||
| 94 | **/ |
||
| 95 | protected $profile; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="skill", cascade={"persist"}) |
||
| 99 | */ |
||
| 100 | protected $issuedSkills; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public function __toString() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Set name |
||
| 112 | * |
||
| 113 | * @param string $name |
||
| 114 | * @return Skill |
||
| 115 | */ |
||
| 116 | public function setName($name) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Get name |
||
| 125 | * |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | public function getName() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Set shortCode |
||
| 135 | * |
||
| 136 | * @param string $shortCode |
||
| 137 | * @return Skill |
||
| 138 | */ |
||
| 139 | public function setShortCode($shortCode) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Get shortCode |
||
| 148 | * |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | public function getShortCode() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Set description |
||
| 158 | * |
||
| 159 | * @param string $description |
||
| 160 | * @return Skill |
||
| 161 | */ |
||
| 162 | public function setDescription($description) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get description |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function getDescription() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Set accessUrlId |
||
| 181 | * |
||
| 182 | * @param integer $accessUrlId |
||
| 183 | * @return Skill |
||
| 184 | */ |
||
| 185 | public function setAccessUrlId($accessUrlId) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get accessUrlId |
||
| 194 | * |
||
| 195 | * @return integer |
||
| 196 | */ |
||
| 197 | public function getAccessUrlId() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Set icon |
||
| 204 | * |
||
| 205 | * @param string $icon |
||
| 206 | * @return Skill |
||
| 207 | */ |
||
| 208 | public function setIcon($icon) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Get icon |
||
| 217 | * |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | public function getIcon() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get the icon (badge image) URL |
||
| 227 | * @param boolean $getSmall Optional. Allow get the small image |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function getWebIconPath($getSmall = false) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set criteria |
||
| 249 | * |
||
| 250 | * @param string $criteria |
||
| 251 | * @return Skill |
||
| 252 | */ |
||
| 253 | public function setCriteria($criteria) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Get criteria |
||
| 262 | * |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function getCriteria() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Set status |
||
| 272 | * @param integer $status |
||
| 273 | * @return \Chamilo\CoreBundle\Entity\Skill |
||
| 274 | */ |
||
| 275 | public function setStatus($status) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Get status |
||
| 284 | * @return integer |
||
| 285 | */ |
||
| 286 | public function getStatus() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Set updatedAt |
||
| 293 | * @param \DateTime $updatedAt The update datetime |
||
| 294 | * @return \Chamilo\CoreBundle\Entity\Skill |
||
| 295 | */ |
||
| 296 | public function setUpdatedAt(\DateTime $updatedAt) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get updatedAt |
||
| 305 | * @return \DateTime |
||
| 306 | */ |
||
| 307 | public function getUpdatedAt() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Get id |
||
| 314 | * |
||
| 315 | * @return integer |
||
| 316 | */ |
||
| 317 | public function getId() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return Profile |
||
| 324 | */ |
||
| 325 | public function getProfile() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param Profile $profile |
||
| 332 | * |
||
| 333 | * @return Skill |
||
| 334 | */ |
||
| 335 | public function setProfile($profile) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Get issuedSkills |
||
| 344 | * @return ArrayCollection |
||
| 345 | */ |
||
| 346 | public function getIssuedSkills() |
||
| 350 | |||
| 351 | } |
||
| 352 |