Complex classes like ShopifyAPIComponent 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 ShopifyAPIComponent, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class ShopifyAPIComponent extends Component |
||
26 | { |
||
27 | |||
28 | public $apiKey; |
||
29 | |||
30 | private $shopDomain; |
||
31 | private $token; |
||
32 | private $sharedSecret; |
||
33 | private $privateApp; |
||
34 | private $privateAppPassword; |
||
35 | private $nonce; |
||
36 | |||
37 | public $controller = null; |
||
38 | |||
39 | /** |
||
40 | * @param array $config |
||
|
|||
41 | * @return void |
||
42 | */ |
||
43 | 18 | public function initialize(array $config = []) |
|
62 | |||
63 | /** |
||
64 | * @param Event $event |
||
65 | * @return void |
||
66 | */ |
||
67 | 18 | public function startup(Event $event) |
|
71 | |||
72 | /** |
||
73 | * @param controller $controller |
||
74 | * @return void |
||
75 | */ |
||
76 | 18 | public function setController($controller) |
|
80 | |||
81 | /** |
||
82 | * @param string $shopDomain |
||
83 | * @return string|null |
||
84 | */ |
||
85 | 6 | public function setShopDomain($shopDomain) |
|
89 | |||
90 | /** |
||
91 | * @return string|null |
||
92 | */ |
||
93 | 6 | public function getShopDomain() |
|
97 | |||
98 | /** |
||
99 | * @param string $shopDomain |
||
100 | * @return bool |
||
101 | */ |
||
102 | 6 | public function validDomain($shopDomain) |
|
106 | |||
107 | /** |
||
108 | * @param string $token |
||
109 | * @return string|null |
||
110 | */ |
||
111 | public function setAccessToken($token) |
||
115 | |||
116 | /** |
||
117 | * @return string|null |
||
118 | */ |
||
119 | public function getAccessToken() |
||
123 | |||
124 | /** |
||
125 | * @return int|null |
||
126 | */ |
||
127 | public function callsMade() |
||
131 | |||
132 | /** |
||
133 | * @return int|null |
||
134 | */ |
||
135 | public function callLimit() |
||
139 | |||
140 | /** |
||
141 | * @param Response $responseHeaders |
||
142 | * @return int|null |
||
143 | */ |
||
144 | public function callsLeft($responseHeaders) |
||
148 | |||
149 | /** |
||
150 | * @param string $method |
||
151 | * @param string $path |
||
152 | * @param array $params |
||
153 | * @return array|null |
||
154 | */ |
||
155 | public function call($method, $path, $params = []) |
||
183 | |||
184 | /** |
||
185 | * @param int $index |
||
186 | * @return int |
||
187 | */ |
||
188 | private function shopApiCallLimitParam($index) |
||
194 | |||
195 | /** |
||
196 | * @param string $shopDomain |
||
197 | * @param string $redirectUrl |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
||
209 | |||
210 | /** |
||
211 | * @param string $shopDomain |
||
212 | * @param string $code |
||
213 | * @return string|false |
||
214 | */ |
||
215 | public function requestAccessToken($shopDomain, $code) |
||
243 | |||
244 | /** |
||
245 | * @param string $shopDomain |
||
246 | * @return string|null |
||
247 | */ |
||
248 | 6 | public function setNonce($shopDomain) |
|
252 | |||
253 | /** |
||
254 | * @return string|null |
||
255 | */ |
||
256 | public function getNonce() |
||
260 | |||
261 | /** |
||
262 | * @return json |
||
263 | */ |
||
264 | public function getShopData() |
||
268 | 6 | ||
269 | /** |
||
270 | * @param array $query |
||
271 | 6 | * @return bool |
|
272 | */ |
||
273 | 6 | public function validateHMAC($query) |
|
294 | 6 | ||
295 | /** |
||
296 | 6 | * @param string $url |
|
297 | * @return string |
||
298 | */ |
||
299 | private function _urlEncode($url) |
||
306 | |||
307 | /** |
||
308 | * @return bool |
||
309 | */ |
||
310 | private function _isReady() |
||
314 | } |
||
315 |