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 |
||
| 5 | View Code Duplication | class cTelephone |
|
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var TTelephoneType $PhoneType |
||
| 10 | */ |
||
| 11 | protected $PhoneType = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var string $PhoneNo |
||
| 15 | */ |
||
| 16 | protected $PhoneNo = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string $PhoneExt |
||
| 20 | */ |
||
| 21 | protected $PhoneExt = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param TTelephoneType $PhoneType |
||
| 25 | */ |
||
| 26 | public function __construct($PhoneType) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return TTelephoneType |
||
| 33 | */ |
||
| 34 | public function getPhoneType() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param TTelephoneType $PhoneType |
||
| 41 | * @return \Gueststream\PMS\IQWare\API\cTelephone |
||
| 42 | */ |
||
| 43 | public function setPhoneType($PhoneType) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | public function getPhoneNo() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param string $PhoneNo |
||
| 59 | * @return \Gueststream\PMS\IQWare\API\cTelephone |
||
| 60 | */ |
||
| 61 | public function setPhoneNo($PhoneNo) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function getPhoneExt() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param string $PhoneExt |
||
| 77 | * @return \Gueststream\PMS\IQWare\API\cTelephone |
||
| 78 | */ |
||
| 79 | public function setPhoneExt($PhoneExt) |
||
| 84 | } |
||
| 85 |
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.