Complex classes like ConfigService 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 ConfigService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class ConfigService { |
||
| 37 | |||
| 38 | const CIRCLES_ALLOW_CIRCLES = 'allow_circles'; |
||
| 39 | const CIRCLES_CONTACT_BACKEND = 'contact_backend'; |
||
| 40 | const CIRCLES_STILL_FRONTEND = 'still_frontend'; |
||
| 41 | const CIRCLES_SWAP_TO_TEAMS = 'swap_to_teams'; |
||
| 42 | const CIRCLES_ALLOW_FEDERATED_CIRCLES = 'allow_federated'; |
||
| 43 | const CIRCLES_GS_ENABLED = 'gs_enabled'; |
||
| 44 | const CIRCLES_MEMBERS_LIMIT = 'members_limit'; |
||
| 45 | const CIRCLES_ACCOUNTS_ONLY = 'accounts_only'; |
||
| 46 | const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups'; |
||
| 47 | const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; |
||
| 48 | const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; |
||
| 49 | const CIRCLES_SELF_SIGNED = 'self_signed_cert'; |
||
| 50 | const LOCAL_CLOUD_ID = 'local_cloud_id'; |
||
| 51 | const CIRCLES_ACTIVITY_ON_CREATION = 'creation_activity'; |
||
| 52 | const CIRCLES_SKIP_INVITATION_STEP = 'skip_invitation_to_closed_circles'; |
||
| 53 | const CIRCLES_SEARCH_FROM_COLLABORATOR = 'search_from_collaborator'; |
||
| 54 | const CIRCLES_TEST_ASYNC_LOCK = 'test_async_lock'; |
||
| 55 | const CIRCLES_TEST_ASYNC_INIT = 'test_async_init'; |
||
| 56 | const CIRCLES_TEST_ASYNC_HAND = 'test_async_hand'; |
||
| 57 | const CIRCLES_TEST_ASYNC_COUNT = 'test_async_count'; |
||
| 58 | |||
| 59 | const GS_ENABLED = 'enabled'; |
||
| 60 | const GS_MODE = 'mode'; |
||
| 61 | const GS_KEY = 'key'; |
||
| 62 | const GS_LOOKUP = 'lookup'; |
||
| 63 | |||
| 64 | const GS_LOOKUP_INSTANCES = '/instances'; |
||
| 65 | |||
| 66 | |||
| 67 | private $defaults = [ |
||
| 68 | self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL, |
||
| 69 | self::CIRCLES_CONTACT_BACKEND => '0', |
||
| 70 | self::CIRCLES_STILL_FRONTEND => '0', |
||
| 71 | self::CIRCLES_TEST_ASYNC_INIT => '0', |
||
| 72 | self::CIRCLES_SWAP_TO_TEAMS => '0', |
||
| 73 | self::CIRCLES_ACCOUNTS_ONLY => '0', |
||
| 74 | self::CIRCLES_MEMBERS_LIMIT => '50', |
||
| 75 | self::CIRCLES_ALLOW_LINKED_GROUPS => '0', |
||
| 76 | self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0', |
||
| 77 | self::CIRCLES_GS_ENABLED => '0', |
||
| 78 | self::CIRCLES_ALLOW_NON_SSL_LINKS => '0', |
||
| 79 | self::CIRCLES_NON_SSL_LOCAL => '0', |
||
| 80 | self::CIRCLES_SELF_SIGNED => '0', |
||
| 81 | self::LOCAL_CLOUD_ID => '', |
||
| 82 | self::CIRCLES_ACTIVITY_ON_CREATION => '1', |
||
| 83 | self::CIRCLES_SKIP_INVITATION_STEP => '0', |
||
| 84 | self::CIRCLES_SEARCH_FROM_COLLABORATOR => '0' |
||
| 85 | ]; |
||
| 86 | |||
| 87 | /** @var string */ |
||
| 88 | private $appName; |
||
| 89 | |||
| 90 | /** @var IConfig */ |
||
| 91 | private $config; |
||
| 92 | |||
| 93 | /** @var string */ |
||
| 94 | private $userId; |
||
| 95 | |||
| 96 | /** @var IRequest */ |
||
| 97 | private $request; |
||
| 98 | |||
| 99 | /** @var MiscService */ |
||
| 100 | private $miscService; |
||
| 101 | |||
| 102 | /** @var int */ |
||
| 103 | private $allowedCircle = -1; |
||
| 104 | |||
| 105 | /** @var int */ |
||
| 106 | private $allowedLinkedGroups = -1; |
||
| 107 | |||
| 108 | /** @var int */ |
||
| 109 | private $allowedFederatedCircles = -1; |
||
| 110 | |||
| 111 | /** @var int */ |
||
| 112 | private $allowedNonSSLLinks = -1; |
||
| 113 | |||
| 114 | /** @var int */ |
||
| 115 | private $localNonSSL = -1; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * ConfigService constructor. |
||
| 119 | * |
||
| 120 | * @param string $appName |
||
| 121 | * @param IConfig $config |
||
| 122 | * @param IRequest $request |
||
| 123 | * @param string $userId |
||
| 124 | * @param MiscService $miscService |
||
| 125 | */ |
||
| 126 | public function __construct( |
||
| 135 | |||
| 136 | |||
| 137 | public function getLocalAddress() { |
||
| 141 | |||
| 142 | |||
| 143 | /** |
||
| 144 | * returns if this type of circle is allowed by the current configuration. |
||
| 145 | * |
||
| 146 | * @param $type |
||
| 147 | * |
||
| 148 | * @return int |
||
| 149 | */ |
||
| 150 | public function isCircleAllowed($type) { |
||
| 157 | |||
| 158 | |||
| 159 | /** |
||
| 160 | * @return bool |
||
| 161 | * @throws GSStatusException |
||
| 162 | */ |
||
| 163 | public function isLinkedGroupsAllowed() { |
||
| 172 | |||
| 173 | |||
| 174 | /** |
||
| 175 | * @return bool |
||
| 176 | */ |
||
| 177 | public function isFederatedCirclesAllowed() { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | public function isInvitationSkipped() { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return bool |
||
| 195 | */ |
||
| 196 | public function isLocalNonSSL() { |
||
| 204 | |||
| 205 | |||
| 206 | /** |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | public function isNonSSLLinksAllowed() { |
||
| 217 | |||
| 218 | |||
| 219 | /** |
||
| 220 | * @param string $remote |
||
| 221 | * |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function generateRemoteHost($remote) { |
||
| 233 | |||
| 234 | |||
| 235 | /** |
||
| 236 | * Get a value by key |
||
| 237 | * |
||
| 238 | * @param string $key |
||
| 239 | * |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getCoreValue($key) { |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Get a value by key |
||
| 250 | * |
||
| 251 | * @param string $key |
||
| 252 | * |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | public function getSystemValue($key) { |
||
| 260 | |||
| 261 | |||
| 262 | /** |
||
| 263 | * Get available hosts |
||
| 264 | * |
||
| 265 | * @return array |
||
| 266 | */ |
||
| 267 | public function getAvailableHosts(): array { |
||
| 270 | |||
| 271 | |||
| 272 | /** |
||
| 273 | * Get a value by key |
||
| 274 | * |
||
| 275 | * @param string $key |
||
| 276 | * |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public function getAppValue($key) { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Set a value by key |
||
| 291 | * |
||
| 292 | * @param string $key |
||
| 293 | * @param string $value |
||
| 294 | * |
||
| 295 | * @return void |
||
| 296 | */ |
||
| 297 | public function setAppValue($key, $value) { |
||
| 300 | |||
| 301 | /** |
||
| 302 | * remove a key |
||
| 303 | * |
||
| 304 | * @param string $key |
||
| 305 | * |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | public function deleteAppValue($key) { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Get a user value by key |
||
| 314 | * |
||
| 315 | * @param string $key |
||
| 316 | * |
||
| 317 | * @return string |
||
| 318 | */ |
||
| 319 | public function getUserValue($key) { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Set a user value by key |
||
| 325 | * |
||
| 326 | * @param string $key |
||
| 327 | * @param string $value |
||
| 328 | * |
||
| 329 | * @return string |
||
| 330 | * @throws PreConditionNotMetException |
||
| 331 | */ |
||
| 332 | public function setUserValue($key, $value) { |
||
| 335 | |||
| 336 | |||
| 337 | /** |
||
| 338 | * Get a user value by key and user |
||
| 339 | * |
||
| 340 | * @param string $userId |
||
| 341 | * @param string $key |
||
| 342 | * |
||
| 343 | * @param string $default |
||
| 344 | * |
||
| 345 | * @return string |
||
| 346 | */ |
||
| 347 | public function getCoreValueForUser($userId, $key, $default = '') { |
||
| 350 | |||
| 351 | |||
| 352 | /** |
||
| 353 | * Get a user value by key and user |
||
| 354 | * |
||
| 355 | * @param string $userId |
||
| 356 | * @param string $key |
||
| 357 | * |
||
| 358 | * @return string |
||
| 359 | */ |
||
| 360 | public function getValueForUser($userId, $key) { |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Set a user value by key |
||
| 366 | * |
||
| 367 | * @param string $userId |
||
| 368 | * @param string $key |
||
| 369 | * @param string $value |
||
| 370 | * |
||
| 371 | * @return string |
||
| 372 | * @throws PreConditionNotMetException |
||
| 373 | */ |
||
| 374 | public function setValueForUser($userId, $key, $value) { |
||
| 377 | |||
| 378 | /** |
||
| 379 | * return the cloud version. |
||
| 380 | * if $complete is true, return a string x.y.z |
||
| 381 | * |
||
| 382 | * @param boolean $complete |
||
| 383 | * |
||
| 384 | * @return string|integer |
||
| 385 | */ |
||
| 386 | public function getCloudVersion($complete = false) { |
||
| 395 | |||
| 396 | |||
| 397 | /** |
||
| 398 | * @return bool |
||
| 399 | */ |
||
| 400 | public function isAccountOnly() { |
||
| 403 | |||
| 404 | |||
| 405 | /** |
||
| 406 | * @return bool |
||
| 407 | */ |
||
| 408 | public function isContactsBackend(): bool { |
||
| 411 | |||
| 412 | |||
| 413 | public function contactsBackendType(): int { |
||
| 416 | |||
| 417 | |||
| 418 | /** |
||
| 419 | * @return bool |
||
| 420 | */ |
||
| 421 | public function stillFrontEnd(): bool { |
||
| 432 | |||
| 433 | |||
| 434 | /** |
||
| 435 | * should the password for a mail share be send to the recipient |
||
| 436 | * |
||
| 437 | * @return bool |
||
| 438 | */ |
||
| 439 | public function sendPasswordByMail() { |
||
| 446 | |||
| 447 | /** |
||
| 448 | * do we require a share by mail to be password protected |
||
| 449 | * |
||
| 450 | * @param Circle $circle |
||
| 451 | * |
||
| 452 | * @return bool |
||
| 453 | */ |
||
| 454 | public function enforcePasswordProtection(Circle $circle) { |
||
| 465 | |||
| 466 | |||
| 467 | /** |
||
| 468 | * @param string $type |
||
| 469 | * |
||
| 470 | * @throws GSStatusException |
||
| 471 | */ |
||
| 472 | public function getGSStatus(string $type = '') { |
||
| 508 | |||
| 509 | |||
| 510 | /** |
||
| 511 | * @return array |
||
| 512 | */ |
||
| 513 | public function getTrustedDomains(): array { |
||
| 521 | |||
| 522 | |||
| 523 | /** |
||
| 524 | * @return string |
||
| 525 | */ |
||
| 526 | public function getLocalCloudId(): string { |
||
| 534 | |||
| 535 | |||
| 536 | /** |
||
| 537 | * @return mixed |
||
| 538 | */ |
||
| 539 | public function getInstanceId() { |
||
| 542 | |||
| 543 | } |
||
| 544 | |||
| 545 |