Complex classes like RestAuthorizeRequest 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 RestAuthorizeRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class RestAuthorizeRequest extends AbstractRequest |
||
14 | 6 | { |
|
15 | public function getEndpoint() |
||
19 | 6 | ||
20 | public function getHttpMethod() |
||
24 | 6 | ||
25 | public function getFirstName() |
||
29 | |||
30 | public function setFirstName($value) |
||
34 | 6 | ||
35 | public function getLastName() |
||
39 | |||
40 | public function setLastName($value) |
||
44 | 6 | ||
45 | public function getEmail() |
||
49 | |||
50 | public function setEmail($value) |
||
54 | 6 | ||
55 | public function getReference() |
||
59 | |||
60 | public function setReference($value) |
||
64 | 6 | ||
65 | public function getMeta() |
||
69 | |||
70 | public function setMeta($value) |
||
74 | 6 | ||
75 | public function hasMetaData() |
||
79 | 6 | ||
80 | public function getHasShippingAddress() |
||
84 | 4 | ||
85 | 2 | public function setHasShippingAddress($value) |
|
89 | 6 | ||
90 | 6 | public function getData() |
|
113 | 2 | ||
114 | public function getBillingAddress() |
||
126 | |||
127 | 6 | public function getOrder() |
|
137 | |||
138 | 6 | public function getOrderItems() |
|
151 | |||
152 | protected function convertItemToItemData(ItemInterface $item) |
||
163 | 6 | ||
164 | 2 | public function getOrderShippingDetails() |
|
186 | |||
187 | 6 | public function getConfig() |
|
193 | |||
194 | 6 | public function getMetaData() |
|
198 | |||
199 | 6 | public function getBillingAddressLine1() |
|
203 | |||
204 | 6 | public function getBillingAddressCity() |
|
208 | |||
209 | 6 | public function getBillingAddressState() |
|
213 | |||
214 | public function getBillingAddressPostalCode() |
||
218 | |||
219 | public function getBillingAddressCountry() |
||
223 | |||
224 | public function getBillingAddressFirstName() |
||
228 | |||
229 | public function getBillingAddressLastName() |
||
233 | |||
234 | public function getShippingAddressLine1() |
||
238 | |||
239 | public function getShippingAddressLine2() |
||
243 | |||
244 | public function getShippingAddressCity() |
||
248 | |||
249 | public function getShippingAddressState() |
||
253 | |||
254 | public function getShippingAddressPostalCode() |
||
258 | |||
259 | public function getShippingAddressCountry() |
||
263 | |||
264 | protected function createResponse($data, $headers = [], $status = 404) |
||
268 | } |
||
269 |