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_SWAP_TO_TEAMS = 'swap_to_teams'; |
||
| 40 | const CIRCLES_ALLOW_FEDERATED_CIRCLES = 'allow_federated'; |
||
| 41 | const CIRCLES_GS_ENABLED = 'gs_enabled'; |
||
| 42 | const CIRCLES_MEMBERS_LIMIT = 'members_limit'; |
||
| 43 | const CIRCLES_ACCOUNTS_ONLY = 'accounts_only'; |
||
| 44 | const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups'; |
||
| 45 | const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; |
||
| 46 | const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; |
||
| 47 | const CIRCLES_ACTIVITY_ON_CREATION = 'creation_activity'; |
||
| 48 | const CIRCLES_SKIP_INVITATION_STEP = 'skip_invitation_to_closed_circles'; |
||
| 49 | |||
| 50 | const CIRCLES_TEST_ASYNC_LOCK = 'test_async_lock'; |
||
| 51 | const CIRCLES_TEST_ASYNC_INIT = 'test_async_init'; |
||
| 52 | const CIRCLES_TEST_ASYNC_HAND = 'test_async_hand'; |
||
| 53 | const CIRCLES_TEST_ASYNC_COUNT = 'test_async_count'; |
||
| 54 | |||
| 55 | const GS_ENABLED = 'enabled'; |
||
| 56 | const GS_MODE = 'mode'; |
||
| 57 | const GS_KEY = 'key'; |
||
| 58 | const GS_LOOKUP = 'lookup'; |
||
| 59 | |||
| 60 | |||
| 61 | private $defaults = [ |
||
| 62 | self::CIRCLES_ALLOW_CIRCLES => Circle::CIRCLES_ALL, |
||
| 63 | self::CIRCLES_TEST_ASYNC_INIT => '0', |
||
| 64 | self::CIRCLES_SWAP_TO_TEAMS => '0', |
||
| 65 | self::CIRCLES_ACCOUNTS_ONLY => '0', |
||
| 66 | self::CIRCLES_MEMBERS_LIMIT => '50', |
||
| 67 | self::CIRCLES_ALLOW_LINKED_GROUPS => '0', |
||
| 68 | self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0', |
||
| 69 | self::CIRCLES_GS_ENABLED => '0', |
||
| 70 | self::CIRCLES_ALLOW_NON_SSL_LINKS => '0', |
||
| 71 | self::CIRCLES_NON_SSL_LOCAL => '0', |
||
| 72 | self::CIRCLES_ACTIVITY_ON_CREATION => '1', |
||
| 73 | self::CIRCLES_SKIP_INVITATION_STEP => '0' |
||
| 74 | ]; |
||
| 75 | |||
| 76 | /** @var string */ |
||
| 77 | private $appName; |
||
| 78 | |||
| 79 | /** @var IConfig */ |
||
| 80 | private $config; |
||
| 81 | |||
| 82 | /** @var string */ |
||
| 83 | private $userId; |
||
| 84 | |||
| 85 | /** @var IRequest */ |
||
| 86 | private $request; |
||
| 87 | |||
| 88 | /** @var MiscService */ |
||
| 89 | private $miscService; |
||
| 90 | |||
| 91 | /** @var int */ |
||
| 92 | private $allowedCircle = -1; |
||
| 93 | |||
| 94 | /** @var int */ |
||
| 95 | private $allowedLinkedGroups = -1; |
||
| 96 | |||
| 97 | /** @var int */ |
||
| 98 | private $allowedFederatedCircles = -1; |
||
| 99 | |||
| 100 | /** @var int */ |
||
| 101 | private $allowedNonSSLLinks = -1; |
||
| 102 | |||
| 103 | /** @var int */ |
||
| 104 | private $localNonSSL = -1; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * ConfigService constructor. |
||
| 108 | * |
||
| 109 | * @param string $appName |
||
| 110 | * @param IConfig $config |
||
| 111 | * @param IRequest $request |
||
| 112 | * @param string $userId |
||
| 113 | * @param MiscService $miscService |
||
| 114 | */ |
||
| 115 | public function __construct( |
||
| 124 | |||
| 125 | |||
| 126 | public function getLocalAddress() { |
||
| 130 | |||
| 131 | |||
| 132 | /** |
||
| 133 | * returns if this type of circle is allowed by the current configuration. |
||
| 134 | * |
||
| 135 | * @param $type |
||
| 136 | * |
||
| 137 | * @return int |
||
| 138 | */ |
||
| 139 | public function isCircleAllowed($type) { |
||
| 146 | |||
| 147 | |||
| 148 | /** |
||
| 149 | * @return bool |
||
| 150 | */ |
||
| 151 | public function isLinkedGroupsAllowed() { |
||
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * @return bool |
||
| 163 | */ |
||
| 164 | public function isFederatedCirclesAllowed() { |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return bool |
||
| 175 | */ |
||
| 176 | public function isInvitationSkipped() { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return bool |
||
| 182 | */ |
||
| 183 | public function isLocalNonSSL() { |
||
| 191 | |||
| 192 | |||
| 193 | /** |
||
| 194 | * @return bool |
||
| 195 | */ |
||
| 196 | public function isNonSSLLinksAllowed() { |
||
| 204 | |||
| 205 | |||
| 206 | /** |
||
| 207 | * @param string $remote |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | public function generateRemoteHost($remote) { |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * Get a value by key |
||
| 224 | * |
||
| 225 | * @param string $key |
||
| 226 | * |
||
| 227 | * @return string |
||
| 228 | */ |
||
| 229 | public function getCoreValue($key) { |
||
| 234 | |||
| 235 | |||
| 236 | /** |
||
| 237 | * Get a value by key |
||
| 238 | * |
||
| 239 | * @param string $key |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getAppValue($key) { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Set a value by key |
||
| 255 | * |
||
| 256 | * @param string $key |
||
| 257 | * @param string $value |
||
| 258 | * |
||
| 259 | * @return void |
||
| 260 | */ |
||
| 261 | public function setAppValue($key, $value) { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * remove a key |
||
| 267 | * |
||
| 268 | * @param string $key |
||
| 269 | * |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function deleteAppValue($key) { |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get a user value by key |
||
| 278 | * |
||
| 279 | * @param string $key |
||
| 280 | * |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function getUserValue($key) { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Set a user value by key |
||
| 289 | * |
||
| 290 | * @param string $key |
||
| 291 | * @param string $value |
||
| 292 | * |
||
| 293 | * @return string |
||
| 294 | * @throws PreConditionNotMetException |
||
| 295 | */ |
||
| 296 | public function setUserValue($key, $value) { |
||
| 299 | |||
| 300 | |||
| 301 | /** |
||
| 302 | * Get a user value by key and user |
||
| 303 | * |
||
| 304 | * @param string $userId |
||
| 305 | * @param string $key |
||
| 306 | * |
||
| 307 | * @param string $default |
||
| 308 | * |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | public function getCoreValueForUser($userId, $key, $default = '') { |
||
| 314 | |||
| 315 | |||
| 316 | /** |
||
| 317 | * Get a user value by key and user |
||
| 318 | * |
||
| 319 | * @param string $userId |
||
| 320 | * @param string $key |
||
| 321 | * |
||
| 322 | * @return string |
||
| 323 | */ |
||
| 324 | public function getValueForUser($userId, $key) { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Set a user value by key |
||
| 330 | * |
||
| 331 | * @param string $userId |
||
| 332 | * @param string $key |
||
| 333 | * @param string $value |
||
| 334 | * |
||
| 335 | * @return string |
||
| 336 | * @throws PreConditionNotMetException |
||
| 337 | */ |
||
| 338 | public function setValueForUser($userId, $key, $value) { |
||
| 341 | |||
| 342 | /** |
||
| 343 | * return the cloud version. |
||
| 344 | * if $complete is true, return a string x.y.z |
||
| 345 | * |
||
| 346 | * @param boolean $complete |
||
| 347 | * |
||
| 348 | * @return string|integer |
||
| 349 | */ |
||
| 350 | public function getCloudVersion($complete = false) { |
||
| 359 | |||
| 360 | |||
| 361 | /** |
||
| 362 | * @return bool |
||
| 363 | */ |
||
| 364 | public function isAccountOnly() { |
||
| 367 | |||
| 368 | |||
| 369 | /** |
||
| 370 | * should the password for a mail share be send to the recipient |
||
| 371 | * |
||
| 372 | * @return bool |
||
| 373 | */ |
||
| 374 | public function sendPasswordByMail() { |
||
| 377 | |||
| 378 | /** |
||
| 379 | * do we require a share by mail to be password protected |
||
| 380 | * |
||
| 381 | * @return bool |
||
| 382 | */ |
||
| 383 | public function enforcePasswordProtection() { |
||
| 386 | |||
| 387 | |||
| 388 | /** |
||
| 389 | * @param string $type |
||
| 390 | * |
||
| 391 | * @throws GSStatusException |
||
| 392 | */ |
||
| 393 | public function getGSStatus(string $type = '') { |
||
| 429 | |||
| 430 | |||
| 431 | /** |
||
| 432 | * @return array |
||
| 433 | */ |
||
| 434 | public function getTrustedDomains(): array { |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | public function getLocalCloudId(): string { |
||
| 450 | |||
| 451 | } |
||
| 452 | |||
| 453 |