Conditions | 72 |
Paths | > 20000 |
Total Lines | 219 |
Code Lines | 125 |
Lines | 120 |
Ratio | 54.79 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
98 | function migrate($OSCOM_PayPal) { |
||
99 | $is_payflow = false; |
||
100 | |||
101 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER') ) { |
|
102 | $server = (MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER == 'Live') ? 'LIVE' : 'SANDBOX'; |
||
103 | |||
104 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_API_USERNAME') && defined('MODULE_PAYMENT_PAYPAL_PRO_DP_API_PASSWORD') && defined('MODULE_PAYMENT_PAYPAL_PRO_DP_API_SIGNATURE') ) { |
||
105 | if ( tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_DP_API_USERNAME) && tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_DP_API_PASSWORD) && tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_DP_API_SIGNATURE) ) { |
||
106 | if ( !defined('OSCOM_APP_PAYPAL_' . $server . '_API_USERNAME') || !tep_not_null(constant('OSCOM_APP_PAYPAL_' . $server . '_API_USERNAME')) ) { |
||
107 | if ( !defined('OSCOM_APP_PAYPAL_' . $server . '_API_PASSWORD') || !tep_not_null(constant('OSCOM_APP_PAYPAL_' . $server . '_API_PASSWORD')) ) { |
||
108 | if ( !defined('OSCOM_APP_PAYPAL_' . $server . '_API_SIGNATURE') || !tep_not_null(constant('OSCOM_APP_PAYPAL_' . $server . '_API_SIGNATURE')) ) { |
||
109 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_' . $server . '_API_USERNAME', MODULE_PAYMENT_PAYPAL_PRO_DP_API_USERNAME); |
||
110 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_' . $server . '_API_PASSWORD', MODULE_PAYMENT_PAYPAL_PRO_DP_API_PASSWORD); |
||
111 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_' . $server . '_API_SIGNATURE', MODULE_PAYMENT_PAYPAL_PRO_DP_API_SIGNATURE); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_API_USERNAME'); |
||
118 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_API_PASSWORD'); |
||
119 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_API_SIGNATURE'); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER') ) { |
|
124 | $is_payflow = true; |
||
125 | |||
126 | $server = (MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER == 'Live') ? 'LIVE' : 'SANDBOX'; |
||
127 | |||
128 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VENDOR') && defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_USERNAME') && defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PASSWORD') && defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PARTNER') ) { |
||
129 | if ( tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VENDOR) && tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PASSWORD) && tep_not_null(MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PARTNER) ) { |
||
130 | if ( !defined('OSCOM_APP_PAYPAL_PF_' . $server . '_VENDOR') || !tep_not_null(constant('OSCOM_APP_PAYPAL_PF_' . $server . '_VENDOR')) ) { |
||
131 | if ( !defined('OSCOM_APP_PAYPAL_PF_' . $server . '_PASSWORD') || !tep_not_null(constant('OSCOM_APP_PAYPAL_PF_' . $server . '_PASSWORD')) ) { |
||
132 | if ( !defined('OSCOM_APP_PAYPAL_PF_' . $server . '_PARTNER') || !tep_not_null(constant('OSCOM_APP_PAYPAL_PF_' . $server . '_PARTNER')) ) { |
||
133 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PF_' . $server . '_VENDOR', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VENDOR); |
||
134 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PF_' . $server . '_USER', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_USERNAME); |
||
135 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PF_' . $server . '_PASSWORD', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PASSWORD); |
||
136 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PF_' . $server . '_PARTNER', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PARTNER); |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VENDOR'); |
||
143 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_USERNAME'); |
||
144 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PASSWORD'); |
||
145 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PARTNER'); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_METHOD') ) { |
|
150 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_TRANSACTION_METHOD', (MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_METHOD == 'Sale') ? '1' : '0'); |
||
151 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_METHOD'); |
||
152 | } |
||
153 | |||
154 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_METHOD') ) { |
|
155 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_TRANSACTION_METHOD', (MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_METHOD == 'Sale') ? '1' : '0'); |
||
156 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_METHOD'); |
||
157 | } |
||
158 | |||
159 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_ORDER_STATUS_ID') ) { |
||
160 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_ORDER_STATUS_ID', MODULE_PAYMENT_PAYPAL_PRO_DP_ORDER_STATUS_ID); |
||
161 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_ORDER_STATUS_ID'); |
||
162 | } |
||
163 | |||
164 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ORDER_STATUS_ID') ) { |
||
165 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_ORDER_STATUS_ID', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ORDER_STATUS_ID); |
||
166 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ORDER_STATUS_ID'); |
||
167 | } |
||
168 | |||
169 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_ZONE') ) { |
||
170 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_ZONE', MODULE_PAYMENT_PAYPAL_PRO_DP_ZONE); |
||
171 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_ZONE'); |
||
172 | } |
||
173 | |||
174 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ZONE') ) { |
||
175 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_ZONE', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ZONE); |
||
176 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_ZONE'); |
||
177 | } |
||
178 | |||
179 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_SORT_ORDER') ) { |
||
180 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_SORT_ORDER', MODULE_PAYMENT_PAYPAL_PRO_DP_SORT_ORDER, 'Sort Order', 'Sort order of display (lowest to highest).'); |
||
181 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_SORT_ORDER'); |
||
182 | } |
||
183 | |||
184 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_SORT_ORDER') ) { |
||
185 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_SORT_ORDER', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_SORT_ORDER, 'Sort Order', 'Sort order of display (lowest to highest).'); |
||
186 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_SORT_ORDER'); |
||
187 | } |
||
188 | |||
189 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTIONS_ORDER_STATUS_ID') ) { |
||
190 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTIONS_ORDER_STATUS_ID'); |
||
191 | } |
||
192 | |||
193 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTIONS_ORDER_STATUS_ID') ) { |
||
194 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTIONS_ORDER_STATUS_ID'); |
||
195 | } |
||
196 | |||
197 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_STATUS') ) { |
|
198 | $status = '-1'; |
||
199 | |||
200 | if ( (MODULE_PAYMENT_PAYPAL_PRO_DP_STATUS == 'True') && defined('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER') ) { |
||
201 | if ( MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER == 'Live' ) { |
||
202 | $status = '1'; |
||
203 | } else { |
||
204 | $status = '0'; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_STATUS', $status); |
||
209 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_STATUS'); |
||
210 | } |
||
211 | |||
212 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_STATUS') ) { |
|
213 | $status = '-1'; |
||
214 | |||
215 | if ( (MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_STATUS == 'True') && defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER') ) { |
||
216 | if ( MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER == 'Live' ) { |
||
217 | $status = '1'; |
||
218 | } else { |
||
219 | $status = '0'; |
||
220 | } |
||
221 | } |
||
222 | |||
223 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_STATUS', $status); |
||
224 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_STATUS'); |
||
225 | } |
||
226 | |||
227 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER') ) { |
||
228 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_TRANSACTION_SERVER'); |
||
229 | } |
||
230 | |||
231 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER') ) { |
||
232 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_TRANSACTION_SERVER'); |
||
233 | } |
||
234 | |||
235 | $cards = array('MODULE_PAYMENT_PAYPAL_PRO_DP_CARDTYPE_VISA', |
||
236 | 'MODULE_PAYMENT_PAYPAL_PRO_DP_CARDTYPE_MASTERCARD', |
||
237 | 'MODULE_PAYMENT_PAYPAL_PRO_DP_CARDTYPE_DISCOVER', |
||
238 | 'MODULE_PAYMENT_PAYPAL_PRO_DP_CARDTYPE_AMEX', |
||
239 | 'MODULE_PAYMENT_PAYPAL_PRO_DP_CARDTYPE_MAESTRO'); |
||
240 | |||
241 | $cards_pass = true; |
||
242 | |||
243 | foreach ( $cards as $c ) { |
||
244 | if ( !defined($c) ) { |
||
245 | $cards_pass = false; |
||
246 | break; |
||
247 | } |
||
248 | } |
||
249 | |||
250 | if ( $cards_pass === true ) { |
||
251 | $cards_installed = array(); |
||
252 | |||
253 | foreach ( $cards as $c ) { |
||
254 | if ( constant($c) == 'True' ) { |
||
255 | $cards_installed[] = strtolower(substr($c, strrpos($c, '_')+1)); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_DP_CARDS', implode(';', $cards_installed)); |
||
260 | } |
||
261 | |||
262 | foreach ( $cards as $c ) { |
||
263 | $OSCOM_PayPal->deleteParameter($c); |
||
264 | } |
||
265 | |||
266 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_VERIFY_SSL') ) { |
|
267 | if ( !defined('OSCOM_APP_PAYPAL_VERIFY_SSL') ) { |
||
268 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_VERIFY_SSL', (MODULE_PAYMENT_PAYPAL_PRO_DP_VERIFY_SSL == 'True') ? '1' : '0'); |
||
269 | } |
||
270 | |||
271 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_VERIFY_SSL'); |
||
272 | } |
||
273 | |||
274 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VERIFY_SSL') ) { |
|
275 | if ( !defined('OSCOM_APP_PAYPAL_VERIFY_SSL') ) { |
||
276 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_VERIFY_SSL', (MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VERIFY_SSL == 'True') ? '1' : '0'); |
||
277 | } |
||
278 | |||
279 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_VERIFY_SSL'); |
||
280 | } |
||
281 | |||
282 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_PROXY') ) { |
|
283 | if ( !defined('OSCOM_APP_PAYPAL_PROXY') ) { |
||
284 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PROXY', MODULE_PAYMENT_PAYPAL_PRO_DP_PROXY); |
||
285 | } |
||
286 | |||
287 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_PROXY'); |
||
288 | } |
||
289 | |||
290 | View Code Duplication | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PROXY') ) { |
|
291 | if ( !defined('OSCOM_APP_PAYPAL_PROXY') ) { |
||
292 | $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PROXY', MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PROXY); |
||
293 | } |
||
294 | |||
295 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_PROXY'); |
||
296 | } |
||
297 | |||
298 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_DP_DEBUG_EMAIL') ) { |
||
299 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_DP_DEBUG_EMAIL'); |
||
300 | } |
||
301 | |||
302 | if ( defined('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_DEBUG_EMAIL') ) { |
||
303 | $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_PRO_PAYFLOW_DP_DEBUG_EMAIL'); |
||
304 | } |
||
305 | |||
306 | View Code Duplication | if ( $is_payflow === true ) { |
|
307 | $installed = explode(';', MODULE_PAYMENT_INSTALLED); |
||
308 | $installed_pos = array_search($this->_pm_pf_code . '.php', $installed); |
||
309 | |||
310 | if ( $installed_pos !== false ) { |
||
311 | unset($installed[$installed_pos]); |
||
312 | |||
313 | $OSCOM_PayPal->saveParameter('MODULE_PAYMENT_INSTALLED', implode(';', $installed)); |
||
314 | } |
||
315 | } |
||
316 | } |
||
317 | } |
||
319 |
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.