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 = []) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param int $index |
||
| 166 | * @return int |
||
| 167 | */ |
||
| 168 | private function shopApiCallLimitParam($index) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $shopDomain |
||
| 177 | * @param string $redirectUrl |
||
| 178 | * @return int |
||
| 179 | */ |
||
| 180 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param string $shopDomain |
||
| 191 | * @param string $code |
||
| 192 | * @return string|bool |
||
| 193 | */ |
||
| 194 | public function getAccessToken($shopDomain, $code) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param string $shopDomain |
||
| 220 | * @return string|null |
||
| 221 | */ |
||
| 222 | public function setNonce($shopDomain) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return string|null |
||
| 229 | */ |
||
| 230 | public function getNonce() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param string $shopDomain |
||
| 237 | * @return bool |
||
| 238 | */ |
||
| 239 | public function validDomain($shopDomain) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return json |
||
| 246 | */ |
||
| 247 | public function getShopData() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param array $query |
||
| 254 | * @return bool |
||
| 255 | */ |
||
| 256 | public function validateHMAC($query) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param string $url |
||
| 280 | * @return string |
||
| 281 | */ |
||
| 282 | private function _urlEncode($url) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return bool |
||
| 291 | */ |
||
| 292 | private function _isReady() |
||
| 296 | } |
||
| 297 |
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.