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 |
||
19 | abstract class National extends ComplexAttribute implements IBox |
||
20 | { |
||
21 | /** @var string */ |
||
22 | protected $product; |
||
23 | |||
24 | /** @var Option[] */ |
||
25 | protected $options; |
||
26 | |||
27 | /** @var int */ |
||
28 | protected $weight; |
||
29 | |||
30 | /** @var Day[] */ |
||
31 | private $openingHours; |
||
32 | |||
33 | /** @var string */ |
||
34 | private $desiredDeliveryPlace; |
||
35 | |||
36 | /** |
||
37 | * @param Option[] $options |
||
38 | */ |
||
39 | 2 | public function setOptions($options) |
|
43 | |||
44 | /** |
||
45 | * @return Option[] |
||
46 | */ |
||
47 | 9 | public function getOptions() |
|
51 | |||
52 | /** |
||
53 | * @param Option $option |
||
54 | */ |
||
55 | 4 | public function addOption(Option $option) |
|
59 | |||
60 | /** |
||
61 | * @param string $product |
||
62 | */ |
||
63 | 9 | public function setProduct($product) |
|
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | 9 | public function getProduct() |
|
75 | |||
76 | /** |
||
77 | * @remark should be implemented by the child class |
||
78 | * @return array |
||
79 | */ |
||
80 | 1 | public static function getPossibleProductValues() |
|
84 | |||
85 | /** |
||
86 | * @param int $weight |
||
87 | */ |
||
88 | 7 | public function setWeight($weight) |
|
92 | |||
93 | /** |
||
94 | * @return int |
||
95 | */ |
||
96 | 9 | public function getWeight() |
|
100 | |||
101 | /** |
||
102 | * @param Day[] $openingHours |
||
103 | */ |
||
104 | 1 | public function setOpeningHours(array $openingHours) |
|
108 | |||
109 | /** |
||
110 | * @param Day $day |
||
111 | */ |
||
112 | 2 | public function addOpeningHour(Day $day) |
|
116 | |||
117 | /** |
||
118 | * @return Day[] |
||
119 | */ |
||
120 | 9 | public function getOpeningHours() |
|
124 | |||
125 | /** |
||
126 | * @param string $desiredDeliveryPlace |
||
127 | */ |
||
128 | 2 | public function setDesiredDeliveryPlace($desiredDeliveryPlace) |
|
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | */ |
||
136 | 8 | public function getDesiredDeliveryPlace() |
|
140 | |||
141 | /** |
||
142 | * Return the object as an array for usage in the XML |
||
143 | * |
||
144 | * @param \DomDocument $document |
||
145 | * @param string $prefix |
||
|
|||
146 | * @param string $type |
||
147 | * @return \DomElement |
||
148 | */ |
||
149 | 7 | public function toXML(\DOMDocument $document, $prefix = null, $type = null) |
|
206 | |||
207 | |||
208 | /** |
||
209 | * @param \SimpleXMLElement $nationalXml |
||
210 | * @param National $self |
||
211 | * @return AtHome |
||
212 | * @throws BpostException |
||
213 | * @throws BpostXmlInvalidItemException |
||
214 | */ |
||
215 | 2 | public static function createFromXML(\SimpleXMLElement $nationalXml, self $self = null) |
|
276 | } |
||
277 |
This check looks for
@param
annotations 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.