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 $shop_domain; |
||
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 | 42 | public function initialize(array $config = []) |
|
62 | |||
63 | /** |
||
64 | * @param Event $event |
||
65 | * @return void |
||
66 | */ |
||
67 | public function startup(Event $event) |
||
71 | |||
72 | /** |
||
73 | * @param controller $controller |
||
74 | * @return void |
||
75 | */ |
||
76 | public function setController($controller) |
||
83 | |||
84 | /** |
||
85 | * @param string $shopDomain |
||
86 | * @return string|null |
||
87 | */ |
||
88 | public function setShopDomain($shopDomain) |
||
92 | |||
93 | /** |
||
94 | * @return string|null |
||
95 | */ |
||
96 | public function getShopDomain() |
||
100 | |||
101 | /** |
||
102 | * @param string $token |
||
103 | * @return string|null |
||
104 | */ |
||
105 | public function setAccessToken($token) |
||
109 | |||
110 | /** |
||
111 | * @return int|null |
||
112 | */ |
||
113 | public function callsMade() |
||
117 | |||
118 | /** |
||
119 | * @return int|null |
||
120 | */ |
||
121 | public function callLimit() |
||
125 | |||
126 | /** |
||
127 | * @param Response $responseHeaders |
||
128 | * @return int|null |
||
129 | */ |
||
130 | public function callsLeft($responseHeaders) |
||
134 | |||
135 | /** |
||
136 | * @param string $method |
||
137 | * @param string $path |
||
138 | * @param array $params |
||
139 | * @return array|null |
||
140 | */ |
||
141 | public function call($method, $path, $params = []) |
||
169 | |||
170 | /** |
||
171 | * @param int $index |
||
172 | * @return int |
||
173 | */ |
||
174 | private function shopApiCallLimitParam($index) |
||
180 | |||
181 | /** |
||
182 | * @param string $shopDomain |
||
183 | * @param string $redirectUrl |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
||
195 | |||
196 | /** |
||
197 | * @param string $shopDomain |
||
198 | * @param string $code |
||
199 | * @return string|bool |
||
200 | */ |
||
201 | public function getAccessToken($shopDomain, $code) |
||
229 | |||
230 | /** |
||
231 | * @param string $shopDomain |
||
232 | * @return string|null |
||
233 | */ |
||
234 | public function setNonce($shopDomain) |
||
238 | |||
239 | /** |
||
240 | * @return string|null |
||
241 | */ |
||
242 | public function getNonce() |
||
246 | |||
247 | /** |
||
248 | * @param string $shopDomain |
||
249 | * @return bool |
||
250 | */ |
||
251 | public function validDomain($shopDomain) |
||
255 | |||
256 | /** |
||
257 | * @return json |
||
258 | */ |
||
259 | public function getShopData() |
||
263 | |||
264 | /** |
||
265 | * @param array $query |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function validateHMAC($query) |
||
289 | |||
290 | /** |
||
291 | * @param string $url |
||
292 | * @return string |
||
293 | */ |
||
294 | private function _urlEncode($url) |
||
301 | |||
302 | /** |
||
303 | * @return bool |
||
304 | */ |
||
305 | private function _isReady() |
||
309 | } |
||
310 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.