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 |
||
| 11 | View Code Duplication | class TComplexTypeType |
|
|
|
|||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @property string $name |
||
| 16 | */ |
||
| 17 | private $name = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @property string $typeAccess |
||
| 21 | */ |
||
| 22 | private $typeAccess = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @property \MetadataV2\edm\TDocumentationType $documentation |
||
| 26 | */ |
||
| 27 | private $documentation = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @property \MetadataV2\edm\TComplexTypePropertyType[] $property |
||
| 31 | */ |
||
| 32 | private $property = array( |
||
| 33 | |||
| 34 | ); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Gets as name |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function getName() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Sets a new name |
||
| 48 | * |
||
| 49 | * @param string $name |
||
| 50 | * @return self |
||
| 51 | */ |
||
| 52 | public function setName($name) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Gets as typeAccess |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getTypeAccess() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Sets a new typeAccess |
||
| 70 | * |
||
| 71 | * @param string $typeAccess |
||
| 72 | * @return self |
||
| 73 | */ |
||
| 74 | public function setTypeAccess($typeAccess) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Gets as documentation |
||
| 82 | * |
||
| 83 | * @return \MetadataV2\edm\TDocumentationType |
||
| 84 | */ |
||
| 85 | public function getDocumentation() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Sets a new documentation |
||
| 92 | * |
||
| 93 | * @param \MetadataV2\edm\TDocumentationType $documentation |
||
| 94 | * @return self |
||
| 95 | */ |
||
| 96 | public function setDocumentation(\MetadataV2\edm\TDocumentationType $documentation) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Adds as property |
||
| 104 | * |
||
| 105 | * @return self |
||
| 106 | * @param \MetadataV2\edm\TComplexTypePropertyType $property |
||
| 107 | */ |
||
| 108 | public function addToProperty(\MetadataV2\edm\TComplexTypePropertyType $property) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * isset property |
||
| 116 | * |
||
| 117 | * @param scalar $index |
||
| 118 | * @return boolean |
||
| 119 | */ |
||
| 120 | public function issetProperty($index) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * unset property |
||
| 127 | * |
||
| 128 | * @param scalar $index |
||
| 129 | * @return void |
||
| 130 | */ |
||
| 131 | public function unsetProperty($index) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Gets as property |
||
| 138 | * |
||
| 139 | * @return \MetadataV2\edm\TComplexTypePropertyType[] |
||
| 140 | */ |
||
| 141 | public function getProperty() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Sets a new property |
||
| 148 | * |
||
| 149 | * @param \MetadataV2\edm\TComplexTypePropertyType[] $property |
||
| 150 | * @return self |
||
| 151 | */ |
||
| 152 | public function setProperty(array $property) |
||
| 157 | } |
||
| 158 |
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.