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 $api_key; |
||
| 29 | |||
| 30 | private $shop_domain; |
||
| 31 | private $token; |
||
| 32 | private $shared_secret; |
||
| 33 | private $is_private_app; |
||
| 34 | private $private_app_password; |
||
| 35 | private $nonce; |
||
| 36 | |||
| 37 | public $controller = null; |
||
| 38 | |||
| 39 | public function initialize(array $config = []) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param Event $event |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | public function startup(Event $event) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param $controller |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | public function setController($controller) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $shopDomain |
||
| 82 | * @return string|null |
||
| 83 | */ |
||
| 84 | public function setShopDomain($shopDomain) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return string|null |
||
| 91 | */ |
||
| 92 | public function getShopDomain() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $token |
||
| 99 | * @return string|null |
||
| 100 | */ |
||
| 101 | public function setAccessToken($token) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return int|null |
||
| 108 | */ |
||
| 109 | public function callsMade() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return int|null |
||
| 116 | */ |
||
| 117 | public function callLimit() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param $responseHeaders |
||
| 124 | * @return int|null |
||
| 125 | */ |
||
| 126 | public function callsLeft($responseHeaders) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param string $method |
||
| 133 | * @param string $path |
||
| 134 | * @param array $params |
||
| 135 | * @return array|null |
||
| 136 | */ |
||
| 137 | public function call($method, $path, $params = []) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param int $index |
||
| 168 | * @return int |
||
| 169 | */ |
||
| 170 | private function shopApiCallLimitParam($index) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $shopDomain |
||
| 179 | * @param string $redirectUrl |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $shopDomain |
||
| 194 | * @param string $code |
||
| 195 | * @return string|bool |
||
| 196 | */ |
||
| 197 | public function getAccessToken($shopDomain, $code) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param string $shopDomain |
||
| 227 | * @return string|null |
||
| 228 | */ |
||
| 229 | public function setNonce($shopDomain) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return string|null |
||
| 236 | */ |
||
| 237 | public function getNonce() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $shopDomain |
||
| 244 | * @return bool |
||
| 245 | */ |
||
| 246 | public function validDomain($shopDomain) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return json |
||
| 253 | */ |
||
| 254 | public function getShopData() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param array $query |
||
| 261 | * @return bool |
||
| 262 | */ |
||
| 263 | public function validateHMAC($query) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param string $url |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | private function _urlEncode($url) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @return bool |
||
| 299 | */ |
||
| 300 | private function _isReady() |
||
| 304 | } |
||
| 305 |
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.