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_GROUP_BACKEND = 'group_backend'; |
||
| 42 | const CIRCLES_GROUP_BACKEND_NAME_PREFIX = 'group_backend_name_prefix'; |
||
| 43 | const CIRCLES_GROUP_BACKEND_NAME_SUFFIX = 'group_backend_name_suffix'; |
||
| 44 | const CIRCLES_SWAP_TO_TEAMS = 'swap_to_teams'; |
||
| 45 | const CIRCLES_ALLOW_FEDERATED_CIRCLES = 'allow_federated'; |
||
| 46 | const CIRCLES_MEMBERS_LIMIT = 'members_limit'; |
||
| 47 | const CIRCLES_ACCOUNTS_ONLY = 'accounts_only'; |
||
| 48 | const CIRCLES_ALLOW_FILES_CIRCLES_FILTER = 'allow_files_filtered_by_circles'; |
||
| 49 | const CIRCLES_ALLOW_LISTED_CIRCLES = 'allow_listed_circles'; |
||
| 50 | const CIRCLES_ALLOW_ANY_GROUP_MEMBERS = 'allow_adding_any_group_members'; |
||
| 51 | const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups'; |
||
| 52 | const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; |
||
| 53 | const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; |
||
| 54 | const CIRCLES_ACTIVITY_ON_CREATION = 'creation_activity'; |
||
| 55 | const CIRCLES_SKIP_INVITATION_STEP = 'skip_invitation_to_closed_circles'; |
||
| 56 | |||
| 57 | const CIRCLES_TEST_ASYNC_LOCK = 'test_async_lock'; |
||
| 58 | const CIRCLES_TEST_ASYNC_INIT = 'test_async_init'; |
||
| 59 | const CIRCLES_TEST_ASYNC_HAND = 'test_async_hand'; |
||
| 60 | const CIRCLES_TEST_ASYNC_COUNT = 'test_async_count'; |
||
| 61 | |||
| 62 | private $defaults = [ |
||
| 63 | self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL, |
||
| 64 | self::CIRCLES_CONTACT_BACKEND => '0', |
||
| 65 | self::CIRCLES_STILL_FRONTEND => '0', |
||
| 66 | self::CIRCLES_GROUP_BACKEND => '0', |
||
| 67 | self::CIRCLES_GROUP_BACKEND_NAME_PREFIX => '', |
||
| 68 | self::CIRCLES_GROUP_BACKEND_NAME_SUFFIX => '', |
||
| 69 | self::CIRCLES_TEST_ASYNC_INIT => '0', |
||
| 70 | self::CIRCLES_SWAP_TO_TEAMS => '0', |
||
| 71 | self::CIRCLES_ACCOUNTS_ONLY => '0', |
||
| 72 | self::CIRCLES_MEMBERS_LIMIT => '50', |
||
| 73 | self::CIRCLES_ALLOW_FILES_CIRCLES_FILTER => '1', |
||
| 74 | self::CIRCLES_ALLOW_LISTED_CIRCLES => '1', |
||
| 75 | self::CIRCLES_ALLOW_ANY_GROUP_MEMBERS => '1', |
||
| 76 | self::CIRCLES_ALLOW_LINKED_GROUPS => '0', |
||
| 77 | self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0', |
||
| 78 | self::CIRCLES_ALLOW_NON_SSL_LINKS => '0', |
||
| 79 | self::CIRCLES_NON_SSL_LOCAL => '0', |
||
| 80 | self::CIRCLES_ACTIVITY_ON_CREATION => '1', |
||
| 81 | self::CIRCLES_SKIP_INVITATION_STEP => '0' |
||
| 82 | ]; |
||
| 83 | |||
| 84 | /** @var string */ |
||
| 85 | private $appName; |
||
| 86 | |||
| 87 | /** @var IConfig */ |
||
| 88 | private $config; |
||
| 89 | |||
| 90 | /** @var string */ |
||
| 91 | private $userId; |
||
| 92 | |||
| 93 | /** @var IRequest */ |
||
| 94 | private $request; |
||
| 95 | |||
| 96 | /** @var MiscService */ |
||
| 97 | private $miscService; |
||
| 98 | |||
| 99 | /** @var int */ |
||
| 100 | private $allowedCircle = -1; |
||
| 101 | |||
| 102 | /** @var int */ |
||
| 103 | private $allowFilesFilteredByCircles = -1; |
||
| 104 | |||
| 105 | /** @var int */ |
||
| 106 | private $allowedListedCircles = -1; |
||
| 107 | |||
| 108 | /** @var int */ |
||
| 109 | private $allowAddingAnyGroupMembers = -1; |
||
| 110 | |||
| 111 | /** @var int */ |
||
| 112 | private $allowedLinkedGroups = -1; |
||
| 113 | |||
| 114 | /** @var int */ |
||
| 115 | private $allowedFederatedCircles = -1; |
||
| 116 | |||
| 117 | /** @var int */ |
||
| 118 | private $allowedNonSSLLinks = -1; |
||
| 119 | |||
| 120 | /** @var int */ |
||
| 121 | private $localNonSSL = -1; |
||
| 122 | |||
| 123 | /** @var string */ |
||
| 124 | private $groupBackendNamePrefix = null; |
||
| 125 | |||
| 126 | /** @var string */ |
||
| 127 | private $groupBackendNameSuffix = null; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * ConfigService constructor. |
||
| 131 | * |
||
| 132 | * @param string $appName |
||
| 133 | * @param IConfig $config |
||
| 134 | * @param IRequest $request |
||
| 135 | * @param string $userId |
||
| 136 | * @param MiscService $miscService |
||
| 137 | */ |
||
| 138 | public function __construct( |
||
| 147 | |||
| 148 | |||
| 149 | public function getLocalAddress() { |
||
| 153 | |||
| 154 | |||
| 155 | /** |
||
| 156 | * returns if this type of circle is allowed by the current configuration. |
||
| 157 | * |
||
| 158 | * @param $type |
||
| 159 | * |
||
| 160 | * @return int |
||
| 161 | */ |
||
| 162 | public function isCircleAllowed($type) { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * returns if the files list could be filtered by circles |
||
| 172 | * |
||
| 173 | * @return bool |
||
| 174 | */ |
||
| 175 | public function isFilesFilteredCirclesAllowed() { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * returns if the circles are allowed to be listed outside the Circles application. |
||
| 186 | * |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | public function isListedCirclesAllowed() { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * returns if the current user is allowed to add any group members. |
||
| 200 | * even if he isn't a member of these groups |
||
| 201 | * |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | public function isAddingAnyGroupMembersAllowed() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | public function isLinkedGroupsAllowed() { |
||
| 224 | |||
| 225 | |||
| 226 | /** |
||
| 227 | * @return bool |
||
| 228 | */ |
||
| 229 | public function isFederatedCirclesAllowed() { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @return bool |
||
| 240 | */ |
||
| 241 | public function isInvitationSkipped() { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return bool |
||
| 247 | */ |
||
| 248 | public function isLocalNonSSL() { |
||
| 256 | |||
| 257 | |||
| 258 | /** |
||
| 259 | * @return bool |
||
| 260 | */ |
||
| 261 | public function isNonSSLLinksAllowed() { |
||
| 269 | |||
| 270 | |||
| 271 | /** |
||
| 272 | * @param string $remote |
||
| 273 | * |
||
| 274 | * @return string |
||
| 275 | */ |
||
| 276 | public function generateRemoteHost($remote) { |
||
| 285 | |||
| 286 | |||
| 287 | /** |
||
| 288 | * Get a value by key |
||
| 289 | * |
||
| 290 | * @param string $key |
||
| 291 | * |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | public function getCoreValue($key) { |
||
| 299 | |||
| 300 | |||
| 301 | /** |
||
| 302 | * Get available hosts |
||
| 303 | * |
||
| 304 | * @return array |
||
| 305 | */ |
||
| 306 | public function getAvailableHosts(): array { |
||
| 309 | |||
| 310 | |||
| 311 | /** |
||
| 312 | * Get a value by key |
||
| 313 | * |
||
| 314 | * @param string $key |
||
| 315 | * |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getAppValue($key) { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Set a value by key |
||
| 330 | * |
||
| 331 | * @param string $key |
||
| 332 | * @param string $value |
||
| 333 | * |
||
| 334 | * @return void |
||
| 335 | */ |
||
| 336 | public function setAppValue($key, $value) { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * remove a key |
||
| 342 | * |
||
| 343 | * @param string $key |
||
| 344 | * |
||
| 345 | * @return string |
||
| 346 | */ |
||
| 347 | public function deleteAppValue($key) { |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Get a user value by key |
||
| 353 | * |
||
| 354 | * @param string $key |
||
| 355 | * |
||
| 356 | * @return string |
||
| 357 | */ |
||
| 358 | public function getUserValue($key) { |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Set a user value by key |
||
| 364 | * |
||
| 365 | * @param string $key |
||
| 366 | * @param string $value |
||
| 367 | * |
||
| 368 | * @return string |
||
| 369 | * @throws PreConditionNotMetException |
||
| 370 | */ |
||
| 371 | public function setUserValue($key, $value) { |
||
| 374 | |||
| 375 | |||
| 376 | /** |
||
| 377 | * Get a user value by key and user |
||
| 378 | * |
||
| 379 | * @param string $userId |
||
| 380 | * @param string $key |
||
| 381 | * |
||
| 382 | * @param string $default |
||
| 383 | * |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | public function getCoreValueForUser($userId, $key, $default = '') { |
||
| 389 | |||
| 390 | |||
| 391 | /** |
||
| 392 | * Get a user value by key and user |
||
| 393 | * |
||
| 394 | * @param string $userId |
||
| 395 | * @param string $key |
||
| 396 | * |
||
| 397 | * @return string |
||
| 398 | */ |
||
| 399 | public function getValueForUser($userId, $key) { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Set a user value by key |
||
| 405 | * |
||
| 406 | * @param string $userId |
||
| 407 | * @param string $key |
||
| 408 | * @param string $value |
||
| 409 | * |
||
| 410 | * @return string |
||
| 411 | * @throws PreConditionNotMetException |
||
| 412 | */ |
||
| 413 | public function setValueForUser($userId, $key, $value) { |
||
| 416 | |||
| 417 | /** |
||
| 418 | * return the cloud version. |
||
| 419 | * if $complete is true, return a string x.y.z |
||
| 420 | * |
||
| 421 | * @param boolean $complete |
||
| 422 | * |
||
| 423 | * @return string|integer |
||
| 424 | */ |
||
| 425 | public function getCloudVersion($complete = false) { |
||
| 434 | |||
| 435 | |||
| 436 | /** |
||
| 437 | * @return bool |
||
| 438 | */ |
||
| 439 | public function isAccountOnly() { |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * @return bool |
||
| 446 | */ |
||
| 447 | public function isContactsBackend(): bool { |
||
| 450 | |||
| 451 | |||
| 452 | public function contactsBackendType(): int { |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @return bool |
||
| 458 | */ |
||
| 459 | public function isGroupsBackend(): bool { |
||
| 462 | |||
| 463 | /** |
||
| 464 | * returns the prefix of the group name |
||
| 465 | * |
||
| 466 | * @return string|null |
||
| 467 | */ |
||
| 468 | public function getGroupBackendNamePrefix() { |
||
| 478 | |||
| 479 | /** |
||
| 480 | * returns the suffix of the group name |
||
| 481 | * |
||
| 482 | * @return string|null |
||
| 483 | */ |
||
| 484 | public function getGroupBackendNameSuffix() { |
||
| 491 | |||
| 492 | /** |
||
| 493 | * @return bool |
||
| 494 | */ |
||
| 495 | public function stillFrontEnd(): bool { |
||
| 506 | |||
| 507 | |||
| 508 | /** |
||
| 509 | * should the password for a mail share be send to the recipient |
||
| 510 | * |
||
| 511 | * @return bool |
||
| 512 | */ |
||
| 513 | public function sendPasswordByMail() { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * do we require a share by mail to be password protected |
||
| 523 | * |
||
| 524 | * @return bool |
||
| 525 | */ |
||
| 526 | public function enforcePasswordProtection() { |
||
| 533 | |||
| 534 | |||
| 535 | public function getInstanceId() { |
||
| 538 | |||
| 539 | } |
||
| 540 |