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 |
||
18 | abstract class AbstractRequest implements Request |
||
19 | { |
||
20 | /** @var ShaComposer */ |
||
21 | protected $shaComposer; |
||
22 | |||
23 | protected $ogoneUri; |
||
24 | |||
25 | protected $parameters = array(); |
||
26 | |||
27 | /** Note this is public to allow easy modification, if need be. */ |
||
28 | public $allowedlanguages = array( |
||
29 | 'en_US' => 'English', 'cs_CZ' => 'Czech', 'de_DE' => 'German', |
||
30 | 'dk_DK' => 'Danish', 'el_GR' => 'Greek', 'es_ES' => 'Spanish', |
||
31 | 'fr_FR' => 'French', 'it_IT' => 'Italian', 'ja_JP' => 'Japanese', |
||
32 | 'nl_BE' => 'Flemish', 'nl_NL' => 'Dutch', 'no_NO' => 'Norwegian', |
||
33 | 'pl_PL' => 'Polish', 'pt_PT' => 'Portugese', 'ru_RU' => 'Russian', |
||
34 | 'se_SE' => 'Swedish', 'sk_SK' => 'Slovak', 'tr_TR' => 'Turkish' |
||
35 | ); |
||
36 | |||
37 | protected $ogoneFields = array( |
||
38 | 'pspid', 'orderid', 'com', 'amount', 'currency', 'language', 'cn', 'email', |
||
39 | 'cardno', 'cvc', 'ed', 'ownerzip', 'owneraddress', 'ownercty', 'ownertown', 'ownertelno', |
||
40 | 'homeurl', 'catalogurl', 'accepturl', 'declineurl', 'exceptionurl', 'cancelurl', 'backurl', |
||
41 | 'complus', 'paramplus', 'pm', 'brand', 'title', 'bgcolor', 'txtcolor', 'tblbgcolor', |
||
42 | 'tbltxtcolor', 'buttonbgcolor', 'buttontxtcolor', 'logo', 'fonttype', 'tp', 'paramvar', |
||
43 | 'alias', 'aliasoperation', 'aliasusage', 'aliaspersistedafteruse', 'device', 'pmlisttype', |
||
44 | 'ecom_payment_card_verification', 'operation', 'withroot', 'remote_addr', 'rtimeout', |
||
45 | 'pmlist', 'exclpmlist', 'creditdebit', 'userid', |
||
46 | // DirectLink with 3-D Secure: Extra request parameters. |
||
47 | // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/directlink-3-d/3-d-transaction-flow-via-directlink#extrarequestparameters |
||
48 | 'flag3d', 'http_accept', 'http_user_agent', 'win3ds', |
||
49 | // Optional integration data: Delivery and Invoicing data. |
||
50 | // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/delivery-and-invoicing-data |
||
51 | 'civility', 'cuid', 'ecom_billto_postal_city', 'ecom_billto_postal_countrycode', |
||
52 | 'ecom_billto_postal_name_first', 'ecom_billto_postal_name_last', 'ecom_billto_postal_postalcode', |
||
53 | 'ecom_billto_postal_street_line1', 'ecom_billto_postal_street_number', 'ecom_shipto_dob', |
||
54 | 'ecom_shipto_online_email', 'ecom_shipto_postal_city', 'ecom_shipto_postal_countrycode', |
||
55 | 'ecom_shipto_postal_name_first', 'ecom_shipto_postal_name_last', 'ecom_shipto_postal_name_prefix', |
||
56 | 'ecom_shipto_postal_postalcode', 'ecom_shipto_postal_state', 'ecom_shipto_postal_street_line1', |
||
57 | 'ecom_shipto_postal_street_number', 'ordershipcost', 'ordershipmeth', 'ordershiptaxcode', |
||
58 | // Optional integration data: Order data ("ITEM" parameters). |
||
59 | // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/order-data |
||
60 | 'itemattributes*', 'itemcategory*', 'itemcomments*', 'itemdesc*', 'itemdiscount*', |
||
61 | 'itemid*', 'itemname*', 'itemprice*', 'itemquant*', 'itemquantorig*', |
||
62 | 'itemunitofmeasure*', 'itemvat*', 'itemvatcode*', 'itemweight*', |
||
63 | // Optional integration data: Travel data. |
||
64 | // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/travel-data |
||
65 | 'datatype', 'aiairname', 'aitinum', 'aitidate', 'aiconjti', 'aipasname', |
||
66 | 'aiextrapasname*', 'aichdet', 'aiairtax', 'aivatamnt', 'aivatappl', 'aitypch', |
||
67 | 'aieycd', 'aiirst', 'aiorcity*', 'aiorcityl*', 'aidestcity*', 'aidestcityl*', |
||
68 | 'aistopov*', 'aicarrier*', 'aibookind*', 'aiflnum*', 'aifldate*', 'aiclass*', |
||
69 | // Subscription Manager. |
||
70 | // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/subscription-manager/via-e-commerce-and-directlink#input |
||
71 | 'subscription_id', 'sub_amount', 'sub_com', 'sub_orderid', 'sub_period_unit', |
||
72 | 'sub_period_number', 'sub_period_moment', 'sub_startdate', 'sub_enddate', |
||
73 | 'sub_status', 'sub_comment', |
||
74 | ); |
||
75 | |||
76 | /** @return string */ |
||
77 | 4 | public function getShaSign() |
|
81 | |||
82 | /** @return string */ |
||
83 | 4 | public function getOgoneUri() |
|
87 | |||
88 | /** Ogone uri to send the customer to. Usually PaymentRequest::TEST or PaymentRequest::PRODUCTION */ |
||
89 | 15 | public function setOgoneUri($ogoneUri) |
|
94 | |||
95 | 25 | View Code Duplication | public function setPspid($pspid) |
102 | |||
103 | 6 | public function setSecure() |
|
107 | |||
108 | /** |
||
109 | * ISO code eg nl_BE |
||
110 | */ |
||
111 | 2 | public function setLanguage($language) |
|
118 | |||
119 | /** Alias for setCn */ |
||
120 | 6 | public function setCustomername($customername) |
|
124 | |||
125 | 6 | public function setCn($cn) |
|
129 | |||
130 | public function setHomeurl($homeurl) |
||
137 | |||
138 | 6 | public function setAccepturl($accepturl) |
|
143 | |||
144 | 2 | public function setDeclineurl($declineurl) |
|
149 | |||
150 | 6 | public function setExceptionurl($exceptionurl) |
|
155 | |||
156 | 3 | public function setCancelurl($cancelurl) |
|
161 | |||
162 | 1 | public function setBackurl($backurl) |
|
167 | |||
168 | /** Alias for setParamplus */ |
||
169 | 1 | public function setFeedbackParams(array $feedbackParams) |
|
173 | |||
174 | 1 | public function setParamplus(array $paramplus) |
|
178 | |||
179 | 25 | public function validate() |
|
187 | |||
188 | 23 | View Code Duplication | protected function validateUri($uri) |
197 | |||
198 | 15 | protected function validateOgoneUri($uri) |
|
206 | |||
207 | /** |
||
208 | * Allows setting ogone parameters that don't have a setter -- usually only |
||
209 | * the unimportant ones like bgcolor, which you'd call with setBgcolor() |
||
210 | * |
||
211 | * @param $method |
||
212 | * @param $args |
||
213 | */ |
||
214 | 3 | public function __call($method, $args) |
|
235 | |||
236 | 4 | public function toArray() |
|
241 | } |
||
242 |
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.