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 | View Code Duplication | class CStudentPublicationRelUser |
|
|
|
|||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var integer |
||
| 25 | * |
||
| 26 | * @ORM\Column(name="iid", type="integer") |
||
| 27 | * @ORM\Id |
||
| 28 | * @ORM\GeneratedValue |
||
| 29 | */ |
||
| 30 | private $iid; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var integer |
||
| 34 | * |
||
| 35 | * @ORM\Column(name="id", type="integer", nullable=true) |
||
| 36 | */ |
||
| 37 | private $id; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var integer |
||
| 41 | * |
||
| 42 | * @ORM\Column(name="c_id", type="integer") |
||
| 43 | */ |
||
| 44 | private $cId; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var integer |
||
| 48 | * |
||
| 49 | * @ORM\Column(name="work_id", type="integer", nullable=false) |
||
| 50 | */ |
||
| 51 | private $workId; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var integer |
||
| 55 | * |
||
| 56 | * @ORM\Column(name="user_id", type="integer", nullable=false) |
||
| 57 | */ |
||
| 58 | private $userId; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Set workId |
||
| 62 | * |
||
| 63 | * @param integer $workId |
||
| 64 | * @return CStudentPublicationRelUser |
||
| 65 | */ |
||
| 66 | public function setWorkId($workId) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get workId |
||
| 75 | * |
||
| 76 | * @return integer |
||
| 77 | */ |
||
| 78 | public function getWorkId() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Set userId |
||
| 85 | * |
||
| 86 | * @param integer $userId |
||
| 87 | * @return CStudentPublicationRelUser |
||
| 88 | */ |
||
| 89 | public function setUserId($userId) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get userId |
||
| 98 | * |
||
| 99 | * @return integer |
||
| 100 | */ |
||
| 101 | public function getUserId() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Set cId |
||
| 108 | * |
||
| 109 | * @param integer $cId |
||
| 110 | * @return CStudentPublicationRelUser |
||
| 111 | */ |
||
| 112 | public function setCId($cId) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get cId |
||
| 121 | * |
||
| 122 | * @return integer |
||
| 123 | */ |
||
| 124 | public function getCId() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get id |
||
| 131 | * |
||
| 132 | * @return integer |
||
| 133 | */ |
||
| 134 | public function getId() |
||
| 138 | } |
||
| 139 |
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.