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 |
||
| 20 | class International implements IBox |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $product; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | private $options; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \Bpost\BpostApiClient\Bpost\Order\Receiver |
||
| 34 | */ |
||
| 35 | private $receiver; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | private $parcelWeight; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var \Bpost\BpostApiClient\Bpost\Order\Box\CustomsInfo\CustomsInfo |
||
| 44 | */ |
||
| 45 | private $customsInfo; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param \Bpost\BpostApiClient\Bpost\Order\Box\CustomsInfo\CustomsInfo $customsInfo |
||
| 49 | */ |
||
| 50 | 1 | public function setCustomsInfo($customsInfo) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @return \Bpost\BpostApiClient\Bpost\Order\Box\CustomsInfo\CustomsInfo |
||
| 57 | */ |
||
| 58 | 2 | public function getCustomsInfo() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @param Option[] $options |
||
| 65 | */ |
||
| 66 | 1 | public function setOptions($options) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * @return Option[] |
||
| 73 | */ |
||
| 74 | 2 | public function getOptions() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @param Option $option |
||
| 81 | */ |
||
| 82 | 1 | public function addOption(Option $option) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * @param int $parcelWeight |
||
| 89 | */ |
||
| 90 | 1 | public function setParcelWeight($parcelWeight) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @return int |
||
| 97 | */ |
||
| 98 | 2 | public function getParcelWeight() |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @param string $product |
||
| 105 | * @throws BpostInvalidValueException |
||
| 106 | */ |
||
| 107 | 3 | public function setProduct($product) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | 2 | public function getProduct() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | 3 | public static function getPossibleProductValues() |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @param \Bpost\BpostApiClient\Bpost\Order\Receiver $receiver |
||
| 139 | */ |
||
| 140 | 2 | public function setReceiver($receiver) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * @return \Bpost\BpostApiClient\Bpost\Order\Receiver |
||
| 147 | */ |
||
| 148 | 2 | public function getReceiver() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Return the object as an array for usage in the XML |
||
| 155 | * |
||
| 156 | * @param \DomDocument $document |
||
| 157 | * @param string $prefix |
||
|
|
|||
| 158 | * @return \DomElement |
||
| 159 | */ |
||
| 160 | 2 | public function toXML(\DOMDocument $document, $prefix = null) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @param \SimpleXMLElement $xml |
||
| 217 | * |
||
| 218 | * @return International |
||
| 219 | * @throws BpostInvalidValueException |
||
| 220 | * @throws BpostNotImplementedException |
||
| 221 | */ |
||
| 222 | public static function createFromXML(\SimpleXMLElement $xml) |
||
| 273 | } |
||
| 274 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.