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 | trait TFunctionImportAttributesTrait |
||
| 12 | { |
||
| 13 | use TSimpleIdentifierTrait, AccessTypeTraits, IsOKToolboxTrait; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @property string $name |
||
| 17 | */ |
||
| 18 | private $name = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType[] $returnType |
||
| 22 | */ |
||
| 23 | private $returnType = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType $entitySet |
||
| 27 | */ |
||
| 28 | private $entitySet = null; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @property boolean $isComposable |
||
| 32 | */ |
||
| 33 | private $isComposable = false; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @property boolean $isSideEffecting |
||
| 37 | */ |
||
| 38 | private $isSideEffecting = true; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @property boolean $isBindable |
||
| 42 | */ |
||
| 43 | private $isBindable = false; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @property string $methodAccess |
||
| 47 | */ |
||
| 48 | private $methodAccess = null; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Gets as name |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | public function getName() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Sets a new name |
||
| 62 | * |
||
| 63 | * @param string $name |
||
| 64 | * @return self |
||
| 65 | */ |
||
| 66 | public function setName($name) |
||
| 67 | { |
||
| 68 | $msg = null; |
||
|
|
|||
| 69 | if (!$this->isTSimpleIdentifierValid($name)) { |
||
| 70 | $msg = "Name must be a valid TSimpleIdentifier"; |
||
| 71 | throw new \InvalidArgumentException($msg); |
||
| 72 | } |
||
| 73 | $this->name = $name; |
||
| 74 | return $this; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Adds as returnType |
||
| 79 | * |
||
| 80 | * @return self |
||
| 81 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType $returnType |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function addToReturnType(TFunctionImportReturnTypeType $returnType) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * isset returnType |
||
| 95 | * |
||
| 96 | * @param scalar $index |
||
| 97 | * @return boolean |
||
| 98 | */ |
||
| 99 | public function issetReturnType($index) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * unset returnType |
||
| 106 | * |
||
| 107 | * @param scalar $index |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | public function unsetReturnType($index) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Gets as returnType |
||
| 117 | * |
||
| 118 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType[] |
||
| 119 | */ |
||
| 120 | public function getReturnType() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Sets a new returnType |
||
| 127 | * |
||
| 128 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType[] $returnType |
||
| 129 | * @return self |
||
| 130 | */ |
||
| 131 | public function setReturnType(array $returnType) |
||
| 132 | { |
||
| 133 | $msg = null; |
||
| 134 | if (!$this->isValidArrayOK( |
||
| 135 | $returnType, |
||
| 136 | '\AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType', |
||
| 137 | $msg |
||
| 138 | )) { |
||
| 139 | throw new \InvalidArgumentException($msg); |
||
| 140 | } |
||
| 141 | $this->returnType = $returnType; |
||
| 142 | return $this; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Gets as entitySet |
||
| 147 | * |
||
| 148 | * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType |
||
| 149 | */ |
||
| 150 | public function getEntitySet() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Sets a new entitySet |
||
| 157 | * |
||
| 158 | * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType $entitySet |
||
| 159 | * @return self |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function setEntitySet(TOperandType $entitySet) |
|
| 162 | { |
||
| 163 | $msg = null; |
||
| 164 | if (!$entitySet->isOK($msg)) { |
||
| 165 | throw new \InvalidArgumentException($msg); |
||
| 166 | } |
||
| 167 | $this->entitySet = $entitySet; |
||
| 168 | return $this; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Gets as isComposable |
||
| 173 | * |
||
| 174 | * @return boolean |
||
| 175 | */ |
||
| 176 | public function getIsComposable() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Sets a new isComposable |
||
| 183 | * |
||
| 184 | * @param boolean $isComposable |
||
| 185 | * @return self |
||
| 186 | */ |
||
| 187 | public function setIsComposable($isComposable) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Gets as isSideEffecting |
||
| 195 | * |
||
| 196 | * @return boolean |
||
| 197 | */ |
||
| 198 | public function getIsSideEffecting() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Sets a new isSideEffecting |
||
| 205 | * |
||
| 206 | * @param boolean $isSideEffecting |
||
| 207 | * @return self |
||
| 208 | */ |
||
| 209 | public function setIsSideEffecting($isSideEffecting) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Gets as isBindable |
||
| 217 | * |
||
| 218 | * @return boolean |
||
| 219 | */ |
||
| 220 | public function getIsBindable() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Sets a new isBindable |
||
| 227 | * |
||
| 228 | * @param boolean $isBindable |
||
| 229 | * @return self |
||
| 230 | */ |
||
| 231 | public function setIsBindable($isBindable) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Gets as methodAccess |
||
| 239 | * |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getMethodAccess() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Sets a new methodAccess |
||
| 249 | * |
||
| 250 | * @param string $methodAccess |
||
| 251 | * @return self |
||
| 252 | */ |
||
| 253 | public function setMethodAccess($methodAccess) |
||
| 263 | |||
| 264 | |||
| 265 | public function isTFunctionImportAttributesValid(&$msg) |
||
| 266 | { |
||
| 298 | } |
||
| 299 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.