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_LINKED_GROUPS = 'allow_linked_groups'; |
||
| 49 | const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; |
||
| 50 | const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; |
||
| 51 | const CIRCLES_ACTIVITY_ON_CREATION = 'creation_activity'; |
||
| 52 | const CIRCLES_SKIP_INVITATION_STEP = 'skip_invitation_to_closed_circles'; |
||
| 53 | |||
| 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 | private $defaults = [ |
||
| 60 | self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL, |
||
| 61 | self::CIRCLES_CONTACT_BACKEND => '0', |
||
| 62 | self::CIRCLES_STILL_FRONTEND => '0', |
||
| 63 | self::CIRCLES_GROUP_BACKEND => '0', |
||
| 64 | self::CIRCLES_GROUP_BACKEND_NAME_PREFIX => '', |
||
| 65 | self::CIRCLES_GROUP_BACKEND_NAME_SUFFIX => '', |
||
| 66 | self::CIRCLES_TEST_ASYNC_INIT => '0', |
||
| 67 | self::CIRCLES_SWAP_TO_TEAMS => '0', |
||
| 68 | self::CIRCLES_ACCOUNTS_ONLY => '0', |
||
| 69 | self::CIRCLES_MEMBERS_LIMIT => '50', |
||
| 70 | self::CIRCLES_ALLOW_FILES_CIRCLES_FILTER => '1', |
||
| 71 | self::CIRCLES_ALLOW_LISTED_CIRCLES => '1', |
||
| 72 | self::CIRCLES_ALLOW_ANY_GROUP_MEMBERS => '1', |
||
| 73 | self::CIRCLES_ALLOW_LINKED_GROUPS => '0', |
||
| 74 | self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0', |
||
| 75 | self::CIRCLES_ALLOW_NON_SSL_LINKS => '0', |
||
| 76 | self::CIRCLES_NON_SSL_LOCAL => '0', |
||
| 77 | self::CIRCLES_ACTIVITY_ON_CREATION => '1', |
||
| 78 | self::CIRCLES_SKIP_INVITATION_STEP => '0' |
||
| 79 | ]; |
||
| 80 | |||
| 81 | /** @var string */ |
||
| 82 | private $appName; |
||
| 83 | |||
| 84 | /** @var IConfig */ |
||
| 85 | private $config; |
||
| 86 | |||
| 87 | /** @var string */ |
||
| 88 | private $userId; |
||
| 89 | |||
| 90 | /** @var IRequest */ |
||
| 91 | private $request; |
||
| 92 | |||
| 93 | /** @var MiscService */ |
||
| 94 | private $miscService; |
||
| 95 | |||
| 96 | /** @var int */ |
||
| 97 | private $allowedCircle = -1; |
||
| 98 | |||
| 99 | /** @var int */ |
||
| 100 | private $allowedLinkedGroups = -1; |
||
| 101 | |||
| 102 | /** @var int */ |
||
| 103 | private $allowedFederatedCircles = -1; |
||
| 104 | |||
| 105 | /** @var int */ |
||
| 106 | private $allowedNonSSLLinks = -1; |
||
| 107 | |||
| 108 | /** @var int */ |
||
| 109 | private $localNonSSL = -1; |
||
| 110 | |||
| 111 | /** @var string */ |
||
| 112 | private $groupBackendNamePrefix = null; |
||
| 113 | |||
| 114 | /** @var string */ |
||
| 115 | private $groupBackendNameSuffix = null; |
||
| 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 | */ |
||
| 162 | public function isLinkedGroupsAllowed() { |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * @return bool |
||
| 174 | */ |
||
| 175 | public function isFederatedCirclesAllowed() { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return bool |
||
| 186 | */ |
||
| 187 | public function isInvitationSkipped() { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @return bool |
||
| 193 | */ |
||
| 194 | public function isLocalNonSSL() { |
||
| 202 | |||
| 203 | |||
| 204 | /** |
||
| 205 | * @return bool |
||
| 206 | */ |
||
| 207 | public function isNonSSLLinksAllowed() { |
||
| 215 | |||
| 216 | |||
| 217 | /** |
||
| 218 | * @param string $remote |
||
| 219 | * |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | public function generateRemoteHost($remote) { |
||
| 231 | |||
| 232 | |||
| 233 | /** |
||
| 234 | * Get a value by key |
||
| 235 | * |
||
| 236 | * @param string $key |
||
| 237 | * |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function getCoreValue($key) { |
||
| 245 | |||
| 246 | |||
| 247 | /** |
||
| 248 | * Get available hosts |
||
| 249 | * |
||
| 250 | * @return array |
||
| 251 | */ |
||
| 252 | public function getAvailableHosts(): array { |
||
| 255 | |||
| 256 | |||
| 257 | /** |
||
| 258 | * Get a value by key |
||
| 259 | * |
||
| 260 | * @param string $key |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getAppValue($key) { |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Set a value by key |
||
| 276 | * |
||
| 277 | * @param string $key |
||
| 278 | * @param string $value |
||
| 279 | * |
||
| 280 | * @return void |
||
| 281 | */ |
||
| 282 | public function setAppValue($key, $value) { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * remove a key |
||
| 288 | * |
||
| 289 | * @param string $key |
||
| 290 | * |
||
| 291 | * @return string |
||
| 292 | */ |
||
| 293 | public function deleteAppValue($key) { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get a user value by key |
||
| 299 | * |
||
| 300 | * @param string $key |
||
| 301 | * |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getUserValue($key) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Set a user value by key |
||
| 310 | * |
||
| 311 | * @param string $key |
||
| 312 | * @param string $value |
||
| 313 | * |
||
| 314 | * @return string |
||
| 315 | * @throws PreConditionNotMetException |
||
| 316 | */ |
||
| 317 | public function setUserValue($key, $value) { |
||
| 320 | |||
| 321 | |||
| 322 | /** |
||
| 323 | * Get a user value by key and user |
||
| 324 | * |
||
| 325 | * @param string $userId |
||
| 326 | * @param string $key |
||
| 327 | * |
||
| 328 | * @param string $default |
||
| 329 | * |
||
| 330 | * @return string |
||
| 331 | */ |
||
| 332 | public function getCoreValueForUser($userId, $key, $default = '') { |
||
| 335 | |||
| 336 | |||
| 337 | /** |
||
| 338 | * Get a user value by key and user |
||
| 339 | * |
||
| 340 | * @param string $userId |
||
| 341 | * @param string $key |
||
| 342 | * |
||
| 343 | * @return string |
||
| 344 | */ |
||
| 345 | public function getValueForUser($userId, $key) { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Set a user value by key |
||
| 351 | * |
||
| 352 | * @param string $userId |
||
| 353 | * @param string $key |
||
| 354 | * @param string $value |
||
| 355 | * |
||
| 356 | * @return string |
||
| 357 | * @throws PreConditionNotMetException |
||
| 358 | */ |
||
| 359 | public function setValueForUser($userId, $key, $value) { |
||
| 362 | |||
| 363 | /** |
||
| 364 | * return the cloud version. |
||
| 365 | * if $complete is true, return a string x.y.z |
||
| 366 | * |
||
| 367 | * @param boolean $complete |
||
| 368 | * |
||
| 369 | * @return string|integer |
||
| 370 | */ |
||
| 371 | public function getCloudVersion($complete = false) { |
||
| 380 | |||
| 381 | |||
| 382 | /** |
||
| 383 | * @return bool |
||
| 384 | */ |
||
| 385 | public function isAccountOnly() { |
||
| 388 | |||
| 389 | |||
| 390 | /** |
||
| 391 | * @return bool |
||
| 392 | */ |
||
| 393 | public function isContactsBackend(): bool { |
||
| 396 | |||
| 397 | |||
| 398 | public function contactsBackendType(): int { |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return bool |
||
| 404 | */ |
||
| 405 | public function isGroupsBackend(): bool { |
||
| 408 | |||
| 409 | /** |
||
| 410 | * returns the prefix of the group name |
||
| 411 | * |
||
| 412 | * @return string|null |
||
| 413 | */ |
||
| 414 | public function getGroupBackendNamePrefix() { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * returns the suffix of the group name |
||
| 424 | * |
||
| 425 | * @return string|null |
||
| 426 | */ |
||
| 427 | public function getGroupBackendNameSuffix() { |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @return bool |
||
| 440 | */ |
||
| 441 | public function stillFrontEnd(): bool { |
||
| 452 | |||
| 453 | |||
| 454 | /** |
||
| 455 | * should the password for a mail share be send to the recipient |
||
| 456 | * |
||
| 457 | * @return bool |
||
| 458 | */ |
||
| 459 | public function sendPasswordByMail() { |
||
| 466 | |||
| 467 | /** |
||
| 468 | * do we require a share by mail to be password protected |
||
| 469 | * |
||
| 470 | * @return bool |
||
| 471 | */ |
||
| 472 | public function enforcePasswordProtection() { |
||
| 479 | |||
| 480 | |||
| 481 | public function getInstanceId() { |
||
| 484 | |||
| 485 | } |
||
| 486 |