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 | View Code Duplication | class GetTrackingByRef extends AbstractStructBase |
|
|
|||
21 | { |
||
22 | /** |
||
23 | * The refNo |
||
24 | * Meta informations extracted from the WSDL |
||
25 | * - maxOccurs: 1 |
||
26 | * - minOccurs: 0 |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $refNo; |
||
31 | /** |
||
32 | * The passkey |
||
33 | * Meta informations extracted from the WSDL |
||
34 | * - maxOccurs: 1 |
||
35 | * - minOccurs: 0 |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | public $passkey; |
||
40 | |||
41 | /** |
||
42 | * Constructor method for getTrackingByRef |
||
43 | * |
||
44 | * @uses GetTrackingByRef::setRefNo() |
||
45 | * @uses GetTrackingByRef::setPasskey() |
||
46 | * |
||
47 | * @param string $refNo |
||
48 | * @param string $passkey |
||
49 | */ |
||
50 | public function __construct($refNo = null, $passkey = null) |
||
56 | |||
57 | /** |
||
58 | * Get refNo value |
||
59 | * |
||
60 | * @return string|null |
||
61 | */ |
||
62 | public function getRefNo() |
||
66 | |||
67 | /** |
||
68 | * Set refNo value |
||
69 | * |
||
70 | * @param string $refNo |
||
71 | * |
||
72 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetTrackingByRef |
||
73 | */ |
||
74 | public function setRefNo($refNo = null) |
||
84 | |||
85 | /** |
||
86 | * Get passkey value |
||
87 | * |
||
88 | * @return string|null |
||
89 | */ |
||
90 | public function getPasskey() |
||
94 | |||
95 | /** |
||
96 | * Set passkey value |
||
97 | * |
||
98 | * @param string $passkey |
||
99 | * |
||
100 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetTrackingByRef |
||
101 | */ |
||
102 | public function setPasskey($passkey = null) |
||
112 | |||
113 | /** |
||
114 | * Method called when an object has been exported with var_export() functions |
||
115 | * It allows to return an object instantiated with the values |
||
116 | * |
||
117 | * @see AbstractStructBase::__set_state() |
||
118 | * |
||
119 | * @uses AbstractStructBase::__set_state() |
||
120 | * |
||
121 | * @param array $array the exported values |
||
122 | * |
||
123 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetTrackingByRef |
||
124 | */ |
||
125 | public static function __set_state(array $array) |
||
129 | |||
130 | /** |
||
131 | * Method returning the class name |
||
132 | * |
||
133 | * @return string __CLASS__ |
||
134 | */ |
||
135 | public function __toString() |
||
139 | } |
||
140 |
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.