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 | * |
||
197 | * @return AuthorizeNetCIM_Response |
||
198 | */ |
||
199 | 1 | public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
|
206 | |||
207 | /** |
||
208 | * Get a shipping address. |
||
209 | * |
||
210 | * @param int $customerProfileId |
||
211 | * @param int $customerAddressId |
||
212 | * |
||
213 | * @return AuthorizeNetCIM_Response |
||
214 | */ |
||
215 | public function getCustomerShippingAddress($customerProfileId, $customerAddressId) |
||
222 | |||
223 | /** |
||
224 | * Update a profile. |
||
225 | * |
||
226 | * @param int $customerProfileId |
||
227 | * @param AuthorizeNetCustomer $customerProfile |
||
228 | * |
||
229 | * @return AuthorizeNetCIM_Response |
||
230 | */ |
||
231 | 1 | public function updateCustomerProfile($customerProfileId, $customerProfile) |
|
239 | |||
240 | /** |
||
241 | * Update a payment profile. |
||
242 | * |
||
243 | * @param int $customerProfileId |
||
244 | * @param int $customerPaymentProfileId |
||
245 | * @param AuthorizeNetPaymentProfile $paymentProfile |
||
246 | * @param string $validationMode |
||
247 | * |
||
248 | * @return AuthorizeNetCIM_Response |
||
249 | */ |
||
250 | 2 | public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "none") |
|
260 | |||
261 | /** |
||
262 | * Update a shipping address. |
||
263 | * |
||
264 | * @param int $customerProfileId |
||
265 | * @param int $customerShippingAddressId |
||
266 | * @param AuthorizeNetAddress $shippingAddress |
||
267 | * |
||
268 | * @return AuthorizeNetCIM_Response |
||
269 | */ |
||
270 | 1 | public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) |
|
280 | |||
281 | /** |
||
282 | * Update the status of an existing order that contains multiple transactions with the same splitTenderId. |
||
283 | * |
||
284 | * @param int $splitTenderId |
||
285 | * @param string $splitTenderStatus |
||
286 | * |
||
287 | * @return AuthorizeNetCIM_Response |
||
288 | */ |
||
289 | 1 | public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) |
|
296 | |||
297 | /** |
||
298 | * Validate a customer payment profile. |
||
299 | * |
||
300 | * @param int $customerProfileId |
||
301 | * @param int $customerPaymentProfileId |
||
302 | * @param int $customerShippingAddressId |
||
303 | * @param int $cardCode |
||
304 | * @param string $validationMode |
||
305 | * |
||
306 | * @return AuthorizeNetCIM_Response |
||
307 | */ |
||
308 | public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "testMode") |
||
318 | |||
319 | /** |
||
320 | * Get hosted profile page request token |
||
321 | * |
||
322 | * @param string $customerProfileId |
||
323 | * @param mixed $settings |
||
324 | * |
||
325 | * @return AuthorizeNetCIM_Response |
||
326 | */ |
||
327 | public function getHostedProfilePageRequest($customerProfileId, $settings=0) |
||
343 | |||
344 | /** |
||
345 | * @return string |
||
346 | */ |
||
347 | 7 | protected function _getPostUrl() |
|
351 | |||
352 | /** |
||
353 | * |
||
354 | * |
||
355 | * @param string $response |
||
356 | * |
||
357 | * @return AuthorizeNetCIM_Response |
||
358 | */ |
||
359 | 7 | protected function _handleResponse($response) |
|
363 | |||
364 | /** |
||
365 | * Prepare the XML post string. |
||
366 | */ |
||
367 | 7 | protected function _setPostString() |
|
382 | |||
383 | /** |
||
384 | * Start the SimpleXMLElement that will be posted. |
||
385 | * |
||
386 | * @param string $request_type The action to be performed. |
||
387 | */ |
||
388 | 7 | private function _constructXml($request_type) |
|
397 | |||
398 | /** |
||
399 | * Add an object to an SimpleXMLElement parent element. |
||
400 | * |
||
401 | * @param SimpleXMLElement $destination The parent element. |
||
402 | * @param Object $object An object, array or value. |
||
403 | */ |
||
404 | 5 | private function _addObject($destination, $object) |
|
423 | |||
424 | /** |
||
425 | * Checks whether an array or object contains any values. |
||
426 | * |
||
427 | * @param Object $object |
||
428 | * |
||
429 | * @return bool |
||
430 | */ |
||
431 | 3 | private static function _notEmpty($object) |
|
445 | |||
446 | } |
||
447 | |||
546 |
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.