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) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Set fullname from holder. |
||
| 184 | * |
||
| 185 | * @param string $fullname Holder's full name. |
||
| 186 | * |
||
| 187 | * @return $this |
||
| 188 | */ |
||
| 189 | public function setFullname($fullname) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Set birth date from holder. |
||
| 198 | * |
||
| 199 | * @param \DateTime|string $birthDate Date of birth of the credit card holder. |
||
| 200 | * |
||
| 201 | * @return $this |
||
| 202 | */ |
||
| 203 | public function setBirthDate($birthDate) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Set tax document from holder. |
||
| 216 | * |
||
| 217 | * @param string $number Document number. |
||
| 218 | * @param string $type Document type. |
||
| 219 | * |
||
| 220 | * @return $this |
||
| 221 | */ |
||
| 222 | View Code Duplication | public function setTaxDocument($number, $type = self::TAX_DOCUMENT) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Set phone from holder. |
||
| 233 | * |
||
| 234 | * @param int $areaCode DDD telephone. |
||
| 235 | * @param int $number Telephone number. |
||
| 236 | * @param int $countryCode Country code. |
||
| 237 | * |
||
| 238 | * @return $this |
||
| 239 | */ |
||
| 240 | View Code Duplication | public function setPhone($areaCode, $number, $countryCode = 55) |
|
| 249 | } |
||
| 250 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.