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 |
||
10 | class Holder extends MoipResource |
||
11 | { |
||
12 | /** |
||
13 | * Address Type. |
||
14 | * |
||
15 | * @const string |
||
16 | */ |
||
17 | const ADDRESS_BILLING = 'BILLING'; |
||
18 | |||
19 | /** |
||
20 | * Standard country . |
||
21 | * |
||
22 | * @const string |
||
23 | */ |
||
24 | const ADDRESS_COUNTRY = 'BRA'; |
||
25 | |||
26 | /** |
||
27 | * Standard document type. |
||
28 | * |
||
29 | * @const string |
||
30 | */ |
||
31 | const TAX_DOCUMENT = 'CPF'; |
||
32 | |||
33 | /** |
||
34 | * Initialize a new instance. |
||
35 | */ |
||
36 | public function initialize() |
||
40 | |||
41 | /** |
||
42 | * Add a new address to the holder. |
||
43 | * |
||
44 | * @param string $type Address type: BILLING. |
||
45 | * @param string $street Street address. |
||
46 | * @param string $number Number address. |
||
47 | * @param string $district Neighborhood address. |
||
48 | * @param string $city City address. |
||
49 | * @param string $state State address. |
||
50 | * @param string $zip The zip code billing address. |
||
51 | * @param string $complement Address complement. |
||
52 | * @param string $country Country ISO-alpha3 format, BRA example. |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | View Code Duplication | public function setAddress($type, $street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY) |
|
72 | |||
73 | /** |
||
74 | * Get holder address. |
||
75 | * |
||
76 | * @return \stdClass Holder's address. |
||
77 | */ |
||
78 | public function getBillingAddress() |
||
82 | |||
83 | /** |
||
84 | * Get holser fullname. |
||
85 | * |
||
86 | * @return string Holder's full name. |
||
87 | */ |
||
88 | public function getFullname() |
||
92 | |||
93 | /** |
||
94 | * Get birth date from holder. |
||
95 | * |
||
96 | * @return \DateTime|null Date of birth of the credit card holder. |
||
97 | */ |
||
98 | public function getBirthDate() |
||
102 | |||
103 | /** |
||
104 | * Get phone area code from holder. |
||
105 | * |
||
106 | * @return int DDD telephone. |
||
107 | */ |
||
108 | public function getPhoneAreaCode() |
||
112 | |||
113 | /** |
||
114 | * Get phone country code from holder. |
||
115 | * |
||
116 | * @return int Country code. |
||
117 | */ |
||
118 | public function getPhoneCountryCode() |
||
122 | |||
123 | /** |
||
124 | * Get phone number from holder. |
||
125 | * |
||
126 | * @return int Telephone number. |
||
127 | */ |
||
128 | public function getPhoneNumber() |
||
132 | |||
133 | /** |
||
134 | * Get tax document type from holder. |
||
135 | * |
||
136 | * @return string Type of value: CPF and CNPJ |
||
137 | */ |
||
138 | public function getTaxDocumentType() |
||
142 | |||
143 | /** |
||
144 | * Get tax document number from holder. |
||
145 | * |
||
146 | * @return string Document Number. |
||
147 | */ |
||
148 | public function getTaxDocumentNumber() |
||
152 | |||
153 | /** |
||
154 | * Mount the buyer structure from holder. |
||
155 | * |
||
156 | * @param \stdClass $response |
||
157 | * |
||
158 | * @return Holder information. |
||
159 | */ |
||
160 | protected function populate(stdClass $response) |
||
180 | |||
181 | /** |
||
182 | * Set fullname from holder. |
||
183 | * |
||
184 | * @param string $fullname Holder's full name. |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function setFullname($fullname) |
||
194 | |||
195 | /** |
||
196 | * Set birth date from holder. |
||
197 | * |
||
198 | * @param \DateTime|string $birthDate Date of birth of the credit card holder. |
||
199 | * |
||
200 | * @return $this |
||
201 | */ |
||
202 | View Code Duplication | public function setBirthDate($birthDate) |
|
212 | |||
213 | /** |
||
214 | * Set tax document from holder. |
||
215 | * |
||
216 | * @param string $number Document number. |
||
217 | * @param string $type Document type. |
||
218 | * |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function setTaxDocument($number, $type = self::TAX_DOCUMENT) |
||
229 | |||
230 | /** |
||
231 | * Set phone from holder. |
||
232 | * |
||
233 | * @param int $areaCode DDD telephone. |
||
234 | * @param int $number Telephone number. |
||
235 | * @param int $countryCode Country code. |
||
236 | * |
||
237 | * @return $this |
||
238 | */ |
||
239 | View Code Duplication | public function setPhone($areaCode, $number, $countryCode = 55) |
|
248 | } |
||
249 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.