Complex classes like AuthorizeNetCIM often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AuthorizeNetCIM, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class AuthorizeNetCIM extends AuthorizeNetRequest |
||
|
|||
19 | { |
||
20 | |||
21 | const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; |
||
22 | const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; |
||
23 | |||
24 | |||
25 | private $_xml; |
||
26 | private $_refId = false; |
||
27 | private $_validationMode = "none"; // "none","testMode","liveMode" |
||
28 | private $_extraOptions; |
||
29 | private $_transactionTypes = array( |
||
30 | 'AuthOnly', |
||
31 | 'AuthCapture', |
||
32 | 'CaptureOnly', |
||
33 | 'PriorAuthCapture', |
||
34 | 'Refund', |
||
35 | 'Void', |
||
36 | ); |
||
37 | |||
38 | /** |
||
39 | * Optional. Used if the merchant wants to set a reference ID. |
||
40 | * |
||
41 | * @param string $refId |
||
42 | */ |
||
43 | public function setRefId($refId) |
||
47 | |||
48 | /** |
||
49 | * Create a customer profile. |
||
50 | * |
||
51 | * @param AuthorizeNetCustomer $customerProfile |
||
52 | * @param string $validationMode |
||
53 | * |
||
54 | * @return AuthorizeNetCIM_Response |
||
55 | */ |
||
56 | 5 | public function createCustomerProfile($customerProfile, $validationMode = "none") |
|
64 | |||
65 | /** |
||
66 | * Create a customer payment profile. |
||
67 | * |
||
68 | * @param int $customerProfileId |
||
69 | * @param AuthorizeNetPaymentProfile $paymentProfile |
||
70 | * @param string $validationMode |
||
71 | * |
||
72 | * @return AuthorizeNetCIM_Response |
||
73 | */ |
||
74 | 2 | public function createCustomerPaymentProfile($customerProfileId, $paymentProfile, $validationMode = "none") |
|
83 | |||
84 | /** |
||
85 | * Create a shipping address. |
||
86 | * |
||
87 | * @param int $customerProfileId |
||
88 | * @param AuthorizeNetAddress $shippingAddress |
||
89 | * |
||
90 | * @return AuthorizeNetCIM_Response |
||
91 | */ |
||
92 | 1 | public function createCustomerShippingAddress($customerProfileId, $shippingAddress) |
|
100 | |||
101 | /** |
||
102 | * Create a transaction. |
||
103 | * |
||
104 | * @param string $transactionType |
||
105 | * @param AuthorizeNetTransaction $transaction |
||
106 | * @param string $extraOptionsString |
||
107 | * |
||
108 | * @return AuthorizeNetCIM_Response |
||
109 | */ |
||
110 | 1 | public function createCustomerProfileTransaction($transactionType, $transaction, $extraOptionsString = "") |
|
119 | |||
120 | /** |
||
121 | * Delete a customer profile. |
||
122 | * |
||
123 | * @param int $customerProfileId |
||
124 | * |
||
125 | * @return AuthorizeNetCIM_Response |
||
126 | */ |
||
127 | 2 | public function deleteCustomerProfile($customerProfileId) |
|
133 | |||
134 | /** |
||
135 | * Delete a payment profile. |
||
136 | * |
||
137 | * @param int $customerProfileId |
||
138 | * @param int $customerPaymentProfileId |
||
139 | * |
||
140 | * @return AuthorizeNetCIM_Response |
||
141 | */ |
||
142 | 1 | public function deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
|
149 | |||
150 | /** |
||
151 | * Delete a shipping address. |
||
152 | * |
||
153 | * @param int $customerProfileId |
||
154 | * @param int $customerAddressId |
||
155 | * |
||
156 | * @return AuthorizeNetCIM_Response |
||
157 | */ |
||
158 | 1 | public function deleteCustomerShippingAddress($customerProfileId, $customerAddressId) |
|
165 | |||
166 | /** |
||
167 | * Get all customer profile ids. |
||
168 | * |
||
169 | * @return AuthorizeNetCIM_Response |
||
170 | */ |
||
171 | 2 | public function getCustomerProfileIds() |
|
176 | |||
177 | /** |
||
178 | * Get a customer profile. |
||
179 | * |
||
180 | * @param int $customerProfileId |
||
181 | * |
||
182 | * @return AuthorizeNetCIM_Response |
||
183 | */ |
||
184 | 2 | public function getCustomerProfile($customerProfileId) |
|
190 | |||
191 | /** |
||
192 | * Get a payment profile. |
||
193 | * |
||
194 | * @param int $customerProfileId |
||
195 | * @param int $customerPaymentProfileId |
||
196 | * @param boolean $unmaskExpirationDate |
||
197 | * |
||
198 | * @return AuthorizeNetCIM_Response |
||
199 | 1 | */ |
|
200 | public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $unmaskExpirationDate = false) |
||
211 | |||
212 | /** |
||
213 | * Get a shipping address. |
||
214 | * |
||
215 | * @param int $customerProfileId |
||
216 | * @param int $customerAddressId |
||
217 | * |
||
218 | * @return AuthorizeNetCIM_Response |
||
219 | */ |
||
220 | public function getCustomerShippingAddress($customerProfileId, $customerAddressId) |
||
227 | |||
228 | /** |
||
229 | * Update a profile. |
||
230 | * |
||
231 | 1 | * @param int $customerProfileId |
|
232 | * @param AuthorizeNetCustomer $customerProfile |
||
233 | 1 | * |
|
234 | 1 | * @return AuthorizeNetCIM_Response |
|
235 | 1 | */ |
|
236 | 1 | public function updateCustomerProfile($customerProfileId, $customerProfile) |
|
244 | |||
245 | /** |
||
246 | * Update a payment profile. |
||
247 | * |
||
248 | * @param int $customerProfileId |
||
249 | * @param int $customerPaymentProfileId |
||
250 | 2 | * @param AuthorizeNetPaymentProfile $paymentProfile |
|
251 | * @param string $validationMode |
||
252 | 2 | * |
|
253 | 2 | * @return AuthorizeNetCIM_Response |
|
254 | 2 | */ |
|
255 | 2 | public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "none") |
|
265 | |||
266 | /** |
||
267 | * Update a shipping address. |
||
268 | * |
||
269 | * @param int $customerProfileId |
||
270 | 1 | * @param int $customerShippingAddressId |
|
271 | * @param AuthorizeNetAddress $shippingAddress |
||
272 | * |
||
273 | 1 | * @return AuthorizeNetCIM_Response |
|
274 | 1 | */ |
|
275 | 1 | public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) |
|
285 | |||
286 | /** |
||
287 | * Update the status of an existing order that contains multiple transactions with the same splitTenderId. |
||
288 | * |
||
289 | 1 | * @param int $splitTenderId |
|
290 | * @param string $splitTenderStatus |
||
291 | 1 | * |
|
292 | 1 | * @return AuthorizeNetCIM_Response |
|
293 | 1 | */ |
|
294 | 1 | public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) |
|
301 | |||
302 | /** |
||
303 | * Validate a customer payment profile. |
||
304 | * |
||
305 | * @param int $customerProfileId |
||
306 | * @param int $customerPaymentProfileId |
||
307 | * @param int $customerShippingAddressId |
||
308 | * @param int $cardCode |
||
309 | * @param string $validationMode |
||
310 | * |
||
311 | * @return AuthorizeNetCIM_Response |
||
312 | */ |
||
313 | public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "testMode") |
||
323 | |||
324 | /** |
||
325 | * Get hosted profile page request token |
||
326 | * |
||
327 | * @param string $customerProfileId |
||
328 | * @param mixed $settings |
||
329 | * |
||
330 | * @return AuthorizeNetCIM_Response |
||
331 | */ |
||
332 | public function getHostedProfilePageRequest($customerProfileId, $settings=0) |
||
348 | |||
349 | 7 | /** |
|
350 | * @return string |
||
351 | */ |
||
352 | protected function _getPostUrl() |
||
356 | |||
357 | /** |
||
358 | * |
||
359 | 7 | * |
|
360 | * @param string $response |
||
361 | 7 | * |
|
362 | * @return AuthorizeNetCIM_Response |
||
363 | */ |
||
364 | protected function _handleResponse($response) |
||
368 | |||
369 | 7 | /** |
|
370 | 7 | * Prepare the XML post string. |
|
371 | */ |
||
372 | protected function _setPostString() |
||
387 | |||
388 | 7 | /** |
|
389 | * Start the SimpleXMLElement that will be posted. |
||
390 | 7 | * |
|
391 | 7 | * @param string $request_type The action to be performed. |
|
392 | 7 | */ |
|
393 | 7 | private function _constructXml($request_type) |
|
402 | |||
403 | /** |
||
404 | 5 | * Add an object to an SimpleXMLElement parent element. |
|
405 | * |
||
406 | 5 | * @param SimpleXMLElement $destination The parent element. |
|
407 | 5 | * @param Object $object An object, array or value. |
|
408 | 5 | */ |
|
409 | 5 | private function _addObject($destination, $object) |
|
428 | |||
429 | /** |
||
430 | * Checks whether an array or object contains any values. |
||
431 | 3 | * |
|
432 | * @param Object $object |
||
433 | 3 | * |
|
434 | 3 | * @return bool |
|
435 | 3 | */ |
|
436 | 3 | private static function _notEmpty($object) |
|
450 | |||
451 | } |
||
452 | |||
551 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.