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 |
||
| 22 | class PaymentDataRequest implements BuilderInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Payment Instrument - Block name. |
||
| 26 | */ |
||
| 27 | const PAYMENT_INSTRUMENT = 'paymentInstrument'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Installment count - Number of payment installments. |
||
| 31 | */ |
||
| 32 | const INSTALLMENT_COUNT = 'installmentCount'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Statement descriptor - Invoice description. |
||
| 36 | */ |
||
| 37 | const STATEMENT_DESCRIPTOR = 'statementDescriptor'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Funding instrument - Block name. |
||
| 41 | */ |
||
| 42 | const FUNDING_INSTRUMENT = 'fundingInstrument'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Method - Block Name. |
||
| 46 | */ |
||
| 47 | const METHOD = 'method'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Credit card - Block name. |
||
| 51 | */ |
||
| 52 | const TYPE_CREDIT_CARD = 'creditCard'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Credit card store - Sets whether to store the card. |
||
| 56 | */ |
||
| 57 | const CREDIT_CARD_STORE = 'store'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Credit card hash - Card encryption data. |
||
| 61 | */ |
||
| 62 | const CREDIT_CARD_HASH = 'hash'; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Credit card id - Card Id. |
||
| 66 | */ |
||
| 67 | const CREDIT_CARD_ID = 'id'; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Credit card CVV - Card CVV data. |
||
| 71 | */ |
||
| 72 | const CREDIT_CARD_CVV = 'cvv'; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Credit card holder - Block name. |
||
| 76 | */ |
||
| 77 | const CREDIT_HOLDER = 'holder'; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Credit card holder full name. |
||
| 81 | */ |
||
| 82 | const CREDIT_HOLDER_FULLNAME = 'fullname'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Credit card holder birth date. |
||
| 86 | */ |
||
| 87 | const CREDIT_HOLDER_BIRTH_DATA = 'birthdate'; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Credit card holder tax document - Block name. |
||
| 91 | */ |
||
| 92 | const CREDIT_HOLDER_TAX_DOCUMENT = 'taxDocument'; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Credit card holder tax document type. |
||
| 96 | */ |
||
| 97 | const CREDIT_HOLDER_TAX_DOCUMENT_TYPE = 'type'; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Credit card holder tax document number. |
||
| 101 | */ |
||
| 102 | const CREDIT_HOLDER_TAX_DOCUMENT_NUMBER = 'number'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Credit card holder phone - Block name. |
||
| 106 | */ |
||
| 107 | const CREDIT_HOLDER_PHONE = 'phone'; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Credit card holder phone country code. |
||
| 111 | */ |
||
| 112 | const CREDIT_HOLDER_PHONE_COUNTRY_CODE = 'countryCode'; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Credit card holder phone area code. |
||
| 116 | */ |
||
| 117 | const CREDIT_HOLDER_PHONE_AREA_CODE = 'areaCode'; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Credit card holder phone number. |
||
| 121 | */ |
||
| 122 | const CREDIT_HOLDER_PHONE_NUMBER = 'number'; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Boleto - Block name. |
||
| 126 | */ |
||
| 127 | const TYPE_BOLETO = 'boleto'; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Boleto expiration date - Due date. |
||
| 131 | */ |
||
| 132 | const BOLETO_EXPIRATION_DATE = 'expirationDate'; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Boleto instruction lines - Block name. |
||
| 136 | */ |
||
| 137 | const BOLETO_INSTRUCTION_LINES = 'instructionLines'; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Boleto instruction lines first - First line impression data. |
||
| 141 | */ |
||
| 142 | const BOLETO_INSTRUCTION_LINES_FIRST = 'first'; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Boleto instruction lines second - Second line impression data. |
||
| 146 | */ |
||
| 147 | const BOLETO_INSTRUCTION_LINES_SECOND = 'second'; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Boleto instruction lines third - Third line impression data. |
||
| 151 | */ |
||
| 152 | const BOLETO_INSTRUCTION_LINES_THIRD = 'third'; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Boleto logo Uri - Url logo. |
||
| 156 | */ |
||
| 157 | const BOLETO_LOGO_URI = 'logoUri'; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var SubjectReader |
||
| 161 | */ |
||
| 162 | private $subjectReader; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var OrderAdapterFactory |
||
| 166 | */ |
||
| 167 | private $orderAdapterFactory; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var Config |
||
| 171 | */ |
||
| 172 | private $config; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var Config Boleto |
||
| 176 | */ |
||
| 177 | private $configBoleto; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @var Config Cc |
||
| 181 | */ |
||
| 182 | private $configCc; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param SubjectReader $subjectReader |
||
| 186 | * @param OrderAdapterFactory $orderAdapterFactory |
||
| 187 | * @param Config $config |
||
| 188 | */ |
||
| 189 | View Code Duplication | public function __construct( |
|
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritdoc} |
||
| 205 | */ |
||
| 206 | public function build(array $buildSubject) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Data for Boleto. |
||
| 239 | * |
||
| 240 | * @param $storeId |
||
| 241 | * |
||
| 242 | * @return array |
||
| 243 | */ |
||
| 244 | public function getDataPaymetBoleto($storeId) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Data for CC Vault. |
||
| 270 | * |
||
| 271 | * @param $payment |
||
| 272 | * @param $orderAdapter |
||
| 273 | * @param $storeId |
||
| 274 | * |
||
| 275 | * @return array |
||
| 276 | */ |
||
| 277 | public function getDataPaymetCCVault($payment, $storeId) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Data for CC. |
||
| 301 | * |
||
| 302 | * @param $payment |
||
| 303 | * @param $orderAdapter |
||
| 304 | * @param $storeId |
||
| 305 | * |
||
| 306 | * @return array |
||
| 307 | */ |
||
| 308 | public function getDataPaymetCC($payment, $orderAdapter, $storeId) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Value For Field Address. |
||
| 361 | * |
||
| 362 | * @param $param_telefone |
||
| 363 | * @param $return_ddd |
||
| 364 | * |
||
| 365 | * @return string value |
||
| 366 | */ |
||
| 367 | public function getNumberOrDDD($param_telefone, $return_ddd = false) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * ValueForTaxDocument. |
||
| 394 | * |
||
| 395 | * @param $orderAdapter |
||
| 396 | * |
||
| 397 | * @return value |
||
| 398 | */ |
||
| 399 | View Code Duplication | public function getValueForTaxDocument($orderAdapter) |
|
| 431 | |||
| 432 | /** |
||
| 433 | * StructurePhone. |
||
| 434 | * |
||
| 435 | * @param $phone |
||
| 436 | * |
||
| 437 | * @return array |
||
| 438 | */ |
||
| 439 | public function structurePhone($phone) |
||
| 447 | } |
||
| 448 |
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.