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 $token |
||
| 100 | * @return string|null |
||
| 101 | */ |
||
| 102 | public function setAccessToken($token) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return int|null |
||
| 109 | */ |
||
| 110 | public function callsMade() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return int|null |
||
| 117 | */ |
||
| 118 | public function callLimit() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param Response $responseHeaders |
||
| 125 | * @return int|null |
||
| 126 | */ |
||
| 127 | public function callsLeft($responseHeaders) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param string $method |
||
| 134 | * @param string $path |
||
| 135 | * @param array $params |
||
| 136 | * @return array|null |
||
| 137 | */ |
||
| 138 | public function call($method, $path, $params = []) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param int $index |
||
| 169 | * @return int |
||
| 170 | */ |
||
| 171 | private function shopApiCallLimitParam($index) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param string $shopDomain |
||
| 180 | * @param string $redirectUrl |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param string $shopDomain |
||
| 195 | * @param string $code |
||
| 196 | * @return string|bool |
||
| 197 | */ |
||
| 198 | public function getAccessToken($shopDomain, $code) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param string $shopDomain |
||
| 229 | * @return string|null |
||
| 230 | */ |
||
| 231 | 6 | public function setNonce($shopDomain) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * @return string|null |
||
| 238 | */ |
||
| 239 | public function getNonce() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @param string $shopDomain |
||
| 246 | * @return bool |
||
| 247 | */ |
||
| 248 | 6 | public function validDomain($shopDomain) |
|
| 252 | |||
| 253 | /** |
||
| 254 | * @return json |
||
| 255 | */ |
||
| 256 | public function getShopData() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param array $query |
||
| 263 | * @return bool |
||
| 264 | */ |
||
| 265 | 6 | public function validateHMAC($query) |
|
| 286 | |||
| 287 | /** |
||
| 288 | * @param string $url |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | 6 | private function _urlEncode($url) |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @return bool |
||
| 301 | */ |
||
| 302 | private function _isReady() |
||
| 306 | } |
||
| 307 |