Complex classes like Config 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 Config, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 55 | class Config implements ContextAwareInterface |
||
| 56 | { |
||
| 57 | use ContextTrait; |
||
| 58 | |||
| 59 | const OAUTH_URL = 'oauth_url'; |
||
| 60 | const CLIENT_ID = 'client_id'; |
||
| 61 | const CLIENT_SECRET = 'client_secret'; |
||
| 62 | const SCOPE = 'scope'; |
||
| 63 | const PROJECT = 'project'; |
||
| 64 | const API_URL = 'api_url'; |
||
| 65 | const USER_NAME = 'username'; |
||
| 66 | const PASSWORD = 'password'; |
||
| 67 | const REFRESH_TOKEN = 'refresh_token'; |
||
| 68 | const GRANT_TYPE = 'grant_type'; |
||
| 69 | |||
| 70 | const GRANT_TYPE_CLIENT = 'client_credentials'; |
||
| 71 | const GRANT_TYPE_PASSWORD = 'password'; |
||
| 72 | const GRANT_TYPE_REFRESH = 'refresh_token'; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | protected $clientSecret; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $clientId; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $project; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var array |
||
| 91 | */ |
||
| 92 | protected $scope = ['manage_project']; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $oauthUrl = 'https://auth.sphere.io'; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $apiUrl = 'https://api.sphere.io'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var int |
||
| 106 | */ |
||
| 107 | protected $batchPoolSize = 25; |
||
| 108 | |||
| 109 | protected $adapter; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var bool |
||
| 113 | */ |
||
| 114 | 316 | protected $throwExceptions = false; |
|
| 115 | |||
| 116 | 316 | protected $acceptEncoding = 'gzip'; |
|
| 117 | 316 | ||
| 118 | protected $grantType = 'client_credentials'; |
||
| 119 | 316 | ||
| 120 | 314 | /** |
|
| 121 | 314 | * @var string |
|
| 122 | 1 | */ |
|
| 123 | protected $username; |
||
| 124 | 313 | ||
| 125 | 316 | /** |
|
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | 315 | protected $password; |
|
| 129 | |||
| 130 | /** |
||
| 131 | 314 | * @var string |
|
| 132 | */ |
||
| 133 | 314 | protected $refreshToken; |
|
| 134 | |||
| 135 | 314 | /** |
|
| 136 | * @param array $configValues |
||
| 137 | 314 | * @return static |
|
| 138 | */ |
||
| 139 | 314 | public static function fromArray(array $configValues) |
|
| 155 | |||
| 156 | protected function camelize($scored) |
||
| 171 | 306 | ||
| 172 | /** |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | public function getClientSecret() |
||
| 179 | |||
| 180 | 304 | /** |
|
| 181 | * @param string $clientSecret |
||
| 182 | 304 | * @return $this |
|
| 183 | */ |
||
| 184 | public function setClientSecret($clientSecret) |
||
| 190 | 311 | ||
| 191 | /** |
||
| 192 | * @return string |
||
| 193 | */ |
||
| 194 | public function getClientId() |
||
| 198 | |||
| 199 | 312 | /** |
|
| 200 | * @param string $clientId |
||
| 201 | 312 | * @return $this |
|
| 202 | */ |
||
| 203 | public function setClientId($clientId) |
||
| 209 | 279 | ||
| 210 | 279 | /** |
|
| 211 | * @return string |
||
| 212 | 279 | */ |
|
| 213 | 279 | public function getProject() |
|
| 217 | |||
| 218 | 278 | /** |
|
| 219 | * @param string $project |
||
| 220 | 279 | * @return $this |
|
| 221 | */ |
||
| 222 | public function setProject($project) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | 12 | public function getScope() |
|
| 252 | |||
| 253 | /** |
||
| 254 | 304 | * @param string $scope |
|
| 255 | * @return $this |
||
| 256 | 304 | */ |
|
| 257 | public function setScope($scope) |
||
| 266 | 293 | ||
| 267 | /** |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function getOauthUrl() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param string $oauthUrl |
||
| 283 | 303 | * @return $this |
|
| 284 | */ |
||
| 285 | 303 | public function setOauthUrl($oauthUrl) |
|
| 291 | |||
| 292 | /** |
||
| 293 | 299 | * @return string |
|
| 294 | */ |
||
| 295 | public function getApiUrl() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $apiUrl |
||
| 302 | * @return $this |
||
| 303 | 1 | */ |
|
| 304 | public function setApiUrl($apiUrl) |
||
| 310 | |||
| 311 | /** |
||
| 312 | 1 | * @return bool |
|
| 313 | */ |
||
| 314 | 1 | public function check() |
|
| 330 | |||
| 331 | /** |
||
| 332 | * @return int |
||
| 333 | */ |
||
| 334 | public function getBatchPoolSize() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @param int $batchPoolSize |
||
| 341 | 44 | * @return $this |
|
| 342 | */ |
||
| 343 | 44 | public function setBatchPoolSize($batchPoolSize) |
|
| 349 | |||
| 350 | 9 | /** |
|
| 351 | * @return string |
||
| 352 | 9 | */ |
|
| 353 | public function getAdapter() |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param string $adapter |
||
| 360 | 296 | * @return $this |
|
| 361 | */ |
||
| 362 | 296 | public function setAdapter($adapter) |
|
| 368 | |||
| 369 | /** |
||
| 370 | * @return bool |
||
| 371 | */ |
||
| 372 | public function getThrowExceptions() |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @param bool $throwExceptions |
||
| 379 | 316 | * @return $this |
|
| 380 | */ |
||
| 381 | 316 | public function setThrowExceptions($throwExceptions) |
|
| 387 | |||
| 388 | /** |
||
| 389 | * @return string |
||
| 390 | */ |
||
| 391 | public function getAcceptEncoding() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param string $acceptEncoding |
||
| 398 | * @return $this |
||
| 399 | */ |
||
| 400 | public function setAcceptEncoding($acceptEncoding) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return static |
||
| 409 | */ |
||
| 410 | public static function of() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @return string |
||
| 417 | */ |
||
| 418 | public function getGrantType() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @param string $grantType |
||
| 425 | * @return $this |
||
| 426 | */ |
||
| 427 | public function setGrantType($grantType) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return string |
||
| 436 | */ |
||
| 437 | public function getUsername() |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param string $username |
||
| 444 | * @return $this |
||
| 445 | */ |
||
| 446 | public function setUsername($username) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getPassword() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @param string $password |
||
| 463 | * @return $this |
||
| 464 | */ |
||
| 465 | public function setPassword($password) |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @return string |
||
| 474 | */ |
||
| 475 | public function getRefreshToken() |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @param string $refreshToken |
||
| 482 | * @return $this |
||
| 483 | */ |
||
| 484 | public function setRefreshToken($refreshToken) |
||
| 490 | } |
||
| 491 |