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 |
||
| 15 | View Code Duplication | class OrderStatus extends Base |
|
|
|
|||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | protected $id; |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $description; |
||
| 25 | /** |
||
| 26 | * @var int |
||
| 27 | */ |
||
| 28 | protected $position; |
||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $group; |
||
| 33 | /** |
||
| 34 | * @var bool |
||
| 35 | */ |
||
| 36 | protected $sendMail; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return int |
||
| 40 | */ |
||
| 41 | public function getId() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param int $id |
||
| 48 | * |
||
| 49 | * @return OrderStatus |
||
| 50 | */ |
||
| 51 | public function setId($id) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function getDescription() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $description |
||
| 68 | * |
||
| 69 | * @return OrderStatus |
||
| 70 | */ |
||
| 71 | public function setDescription($description) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return int |
||
| 80 | */ |
||
| 81 | public function getPosition() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param int $position |
||
| 88 | * |
||
| 89 | * @return OrderStatus |
||
| 90 | */ |
||
| 91 | public function setPosition($position) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function getGroup() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param string $group |
||
| 108 | * |
||
| 109 | * @return OrderStatus |
||
| 110 | */ |
||
| 111 | public function setGroup($group) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public function isSendMail() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param bool $sendMail |
||
| 128 | * |
||
| 129 | * @return OrderStatus |
||
| 130 | */ |
||
| 131 | public function setSendMail($sendMail) |
||
| 137 | } |
||
| 138 |
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.