Complex classes like Circle 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 Circle, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 75 | class Circle extends ManagedModel implements IMemberships, IDeserializable, INC22QueryRow, JsonSerializable { |
||
| 76 | |||
| 77 | |||
| 78 | use TArrayTools; |
||
| 79 | use TNC22Deserialize; |
||
| 80 | |||
| 81 | |||
| 82 | const FLAGS_SHORT = 1; |
||
| 83 | const FLAGS_LONG = 2; |
||
| 84 | |||
| 85 | |||
| 86 | // specific value |
||
| 87 | const CFG_CIRCLE = 0; // only for code readability. Circle is locked by default. |
||
| 88 | const CFG_SINGLE = 1; // Circle with only one single member. |
||
| 89 | const CFG_PERSONAL = 2; // Personal circle, only the owner can see it. |
||
| 90 | |||
| 91 | // bitwise |
||
| 92 | const CFG_SYSTEM = 4; // System Circle (not managed by the official front-end). Meaning some config are limited |
||
| 93 | const CFG_VISIBLE = 8; // Visible to everyone, if not visible, people have to know its name to be able to find it |
||
| 94 | const CFG_OPEN = 16; // Circle is open, people can join |
||
| 95 | const CFG_INVITE = 32; // Adding a member generate an invitation that needs to be accepted |
||
| 96 | const CFG_REQUEST = 64; // Request to join Circles needs to be confirmed by a moderator |
||
| 97 | const CFG_FRIEND = 128; // Members of the circle can invite their friends |
||
| 98 | const CFG_PROTECTED = 256; // Password protected to join/request |
||
| 99 | const CFG_NO_OWNER = 512; // no owner, only members |
||
| 100 | const CFG_HIDDEN = 1024; // hidden from listing, but available as a share entity |
||
| 101 | const CFG_BACKEND = 2048; // Fully hidden, only backend Circles |
||
| 102 | const CFG_LOCAL = 4096; // Local even on GlobalScale |
||
| 103 | const CFG_ROOT = 8192; // Circle cannot be inside another Circle |
||
| 104 | const CFG_CIRCLE_INVITE = 16384; // Circle must confirm when invited in another circle |
||
| 105 | const CFG_FEDERATED = 32768; // Federated |
||
| 106 | const CFG_MOUNTPOINT = 65536; // Generate a Files folder for this Circle |
||
| 107 | |||
| 108 | public static $DEF_CFG_MAX = 131071; |
||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * Note: When editing those values, update lib/Application/Capabilities.php |
||
| 113 | * |
||
| 114 | * @see Capabilities::getCapabilitiesCircleConstants() |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | public static $DEF_CFG = [ |
||
| 118 | 1 => 'S|Single', |
||
| 119 | 2 => 'P|Personal', |
||
| 120 | 4 => 'Y|System', |
||
| 121 | 8 => 'V|Visible', |
||
| 122 | 16 => 'O|Open', |
||
| 123 | 32 => 'I|Invite', |
||
| 124 | 64 => 'JR|Join Request', |
||
| 125 | 128 => 'F|Friends', |
||
| 126 | 256 => 'PP|Password Protected', |
||
| 127 | 512 => 'NO|No Owner', |
||
| 128 | 1024 => 'H|Hidden', |
||
| 129 | 2048 => 'T|Backend', |
||
| 130 | 4096 => 'L|Local', |
||
| 131 | 8192 => 'T|Root', |
||
| 132 | 16384 => 'CI|Circle Invite', |
||
| 133 | 32768 => 'F|Federated' |
||
| 134 | ]; |
||
| 135 | |||
| 136 | |||
| 137 | /** |
||
| 138 | * Note: When editing those values, update lib/Application/Capabilities.php |
||
| 139 | * |
||
| 140 | * @see Capabilities::getCapabilitiesCircleConstants() |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | public static $DEF_SOURCE = [ |
||
| 144 | 1 => 'Nextcloud User', |
||
| 145 | 2 => 'Nextcloud Group', |
||
| 146 | 4 => 'Mail Address', |
||
| 147 | 8 => 'Contact', |
||
| 148 | 16 => 'Circle', |
||
| 149 | 10001 => 'Circles App' |
||
| 150 | ]; |
||
| 151 | |||
| 152 | |||
| 153 | public static $DEF_CFG_CORE_FILTER = [ |
||
| 154 | 1, |
||
| 155 | 2, |
||
| 156 | 4 |
||
| 157 | ]; |
||
| 158 | |||
| 159 | public static $DEF_CFG_SYSTEM_FILTER = [ |
||
| 160 | 512, |
||
| 161 | 1024, |
||
| 162 | 2048 |
||
| 163 | ]; |
||
| 164 | |||
| 165 | |||
| 166 | /** @var string */ |
||
| 167 | private $singleId = ''; |
||
| 168 | |||
| 169 | /** @var int */ |
||
| 170 | private $config = 0; |
||
| 171 | |||
| 172 | /** @var string */ |
||
| 173 | private $name = ''; |
||
| 174 | |||
| 175 | /** @var string */ |
||
| 176 | private $displayName = ''; |
||
| 177 | |||
| 178 | /** @var int */ |
||
| 179 | private $source = 0; |
||
| 180 | |||
| 181 | /** @var Member */ |
||
| 182 | private $owner; |
||
| 183 | |||
| 184 | /** @var Member */ |
||
| 185 | private $initiator; |
||
| 186 | |||
| 187 | /** @var array */ |
||
| 188 | private $settings = []; |
||
| 189 | |||
| 190 | /** @var string */ |
||
| 191 | private $description = ''; |
||
| 192 | |||
| 193 | /** @var int */ |
||
| 194 | private $contactAddressBook = 0; |
||
| 195 | |||
| 196 | /** @var string */ |
||
| 197 | private $contactGroupName = ''; |
||
| 198 | |||
| 199 | /** @var string */ |
||
| 200 | private $instance = ''; |
||
| 201 | |||
| 202 | // /** @var bool */ |
||
| 203 | // private $hidden = false; |
||
| 204 | |||
| 205 | /** @var int */ |
||
| 206 | private $creation = 0; |
||
| 207 | |||
| 208 | |||
| 209 | /** @var Member[] */ |
||
| 210 | private $members = null; |
||
| 211 | |||
| 212 | /** @var Member[] */ |
||
| 213 | private $inheritedMembers = null; |
||
| 214 | |||
| 215 | /** @var bool */ |
||
| 216 | private $detailedInheritedMember = false; |
||
| 217 | |||
| 218 | /** @var Membership[] */ |
||
| 219 | private $memberships = null; |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * Circle constructor. |
||
| 224 | */ |
||
| 225 | public function __construct() { |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param string $singleId |
||
| 230 | * |
||
| 231 | * @return self |
||
| 232 | */ |
||
| 233 | public function setSingleId(string $singleId): self { |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getSingleId(): string { |
||
| 245 | |||
| 246 | |||
| 247 | /** |
||
| 248 | * @param int $config |
||
| 249 | * |
||
| 250 | * @return self |
||
| 251 | */ |
||
| 252 | public function setConfig(int $config): self { |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return int |
||
| 260 | */ |
||
| 261 | public function getConfig(): int { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param int $flag |
||
| 267 | * @param int $test |
||
| 268 | * |
||
| 269 | * @return bool |
||
| 270 | */ |
||
| 271 | public function isConfig(int $flag, int $test = 0): bool { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @param int $flag |
||
| 281 | */ |
||
| 282 | public function addConfig(int $flag): void { |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param int $flag |
||
| 290 | */ |
||
| 291 | public function remConfig(int $flag): void { |
||
| 296 | |||
| 297 | |||
| 298 | /** |
||
| 299 | * @param string $name |
||
| 300 | * |
||
| 301 | * @return self |
||
| 302 | */ |
||
| 303 | public function setName(string $name): self { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return string |
||
| 314 | */ |
||
| 315 | public function getName(): string { |
||
| 318 | |||
| 319 | |||
| 320 | /** |
||
| 321 | * @param string $displayName |
||
| 322 | * |
||
| 323 | * @return self |
||
| 324 | */ |
||
| 325 | public function setDisplayName(string $displayName): self { |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @return string |
||
| 335 | */ |
||
| 336 | public function getDisplayName(): string { |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * @param int $source |
||
| 343 | * |
||
| 344 | * @return Circle |
||
| 345 | */ |
||
| 346 | public function setSource(int $source): self { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return int |
||
| 354 | */ |
||
| 355 | public function getSource(): int { |
||
| 358 | |||
| 359 | |||
| 360 | /** |
||
| 361 | * @param ?Member $owner |
||
|
|
|||
| 362 | * |
||
| 363 | * @return self |
||
| 364 | */ |
||
| 365 | public function setOwner(?Member $owner): self { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return Member |
||
| 373 | */ |
||
| 374 | public function getOwner(): Member { |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return bool |
||
| 380 | */ |
||
| 381 | public function hasOwner(): bool { |
||
| 384 | |||
| 385 | |||
| 386 | /** |
||
| 387 | * @return bool |
||
| 388 | */ |
||
| 389 | public function hasMembers(): bool { |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @param array $members |
||
| 395 | * |
||
| 396 | * @return self |
||
| 397 | */ |
||
| 398 | public function setMembers(array $members): IMemberships { |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @return array |
||
| 406 | */ |
||
| 407 | public function getMembers(): array { |
||
| 414 | |||
| 415 | |||
| 416 | /** |
||
| 417 | * @param array $members |
||
| 418 | * @param bool $detailed |
||
| 419 | * |
||
| 420 | * @return self |
||
| 421 | */ |
||
| 422 | public function setInheritedMembers(array $members, bool $detailed): IMemberships { |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param bool $detailed |
||
| 431 | * |
||
| 432 | * @return array |
||
| 433 | */ |
||
| 434 | public function getInheritedMembers(bool $detailed = false): array { |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * @return bool |
||
| 446 | */ |
||
| 447 | public function hasMemberships(): bool { |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @param array $memberships |
||
| 453 | * |
||
| 454 | * @return self |
||
| 455 | */ |
||
| 456 | public function setMemberships(array $memberships): IMemberships { |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @return Membership[] |
||
| 464 | */ |
||
| 465 | public function getMemberships(): array { |
||
| 472 | |||
| 473 | |||
| 474 | /** |
||
| 475 | * @param Member|null $initiator |
||
| 476 | * |
||
| 477 | * @return Circle |
||
| 478 | */ |
||
| 479 | public function setInitiator(?Member $initiator): self { |
||
| 484 | |||
| 485 | /** |
||
| 486 | * @return Member |
||
| 487 | */ |
||
| 488 | public function getInitiator(): Member { |
||
| 491 | |||
| 492 | /** |
||
| 493 | * @return bool |
||
| 494 | */ |
||
| 495 | public function hasInitiator(): bool { |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @param string $instance |
||
| 501 | * |
||
| 502 | * @return Circle |
||
| 503 | */ |
||
| 504 | public function setInstance(string $instance): self { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @return string |
||
| 514 | * @throws OwnerNotFoundException |
||
| 515 | */ |
||
| 516 | public function getInstance(): string { |
||
| 523 | |||
| 524 | |||
| 525 | /** |
||
| 526 | * @param array $settings |
||
| 527 | * |
||
| 528 | * @return self |
||
| 529 | */ |
||
| 530 | public function setSettings(array $settings): self { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @return array |
||
| 538 | */ |
||
| 539 | public function getSettings(): array { |
||
| 542 | |||
| 543 | |||
| 544 | /** |
||
| 545 | * @param string $description |
||
| 546 | * |
||
| 547 | * @return self |
||
| 548 | */ |
||
| 549 | public function setDescription(string $description): self { |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @return string |
||
| 557 | */ |
||
| 558 | public function getDescription(): string { |
||
| 561 | |||
| 562 | |||
| 563 | /** |
||
| 564 | * @param int $contactAddressBook |
||
| 565 | * |
||
| 566 | * @return self |
||
| 567 | */ |
||
| 568 | public function setContactAddressBook(int $contactAddressBook): self { |
||
| 573 | |||
| 574 | /** |
||
| 575 | * @return int |
||
| 576 | */ |
||
| 577 | public function getContactAddressBook(): int { |
||
| 580 | |||
| 581 | |||
| 582 | /** |
||
| 583 | * @param string $contactGroupName |
||
| 584 | * |
||
| 585 | * @return self |
||
| 586 | */ |
||
| 587 | public function setContactGroupName(string $contactGroupName): self { |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @return string |
||
| 595 | */ |
||
| 596 | public function getContactGroupName(): string { |
||
| 599 | |||
| 600 | |||
| 601 | /** |
||
| 602 | * @param int $creation |
||
| 603 | * |
||
| 604 | * @return self |
||
| 605 | */ |
||
| 606 | public function setCreation(int $creation): self { |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @return int |
||
| 614 | */ |
||
| 615 | public function getCreation(): int { |
||
| 618 | |||
| 619 | |||
| 620 | /** |
||
| 621 | * @param array $data |
||
| 622 | * |
||
| 623 | * @return $this |
||
| 624 | * @throws InvalidItemException |
||
| 625 | */ |
||
| 626 | public function import(array $data): IDeserializable { |
||
| 658 | |||
| 659 | |||
| 660 | /** |
||
| 661 | * @return array |
||
| 662 | */ |
||
| 663 | public function jsonSerialize(): array { |
||
| 694 | |||
| 695 | |||
| 696 | /** |
||
| 697 | * @param array $data |
||
| 698 | * @param string $prefix |
||
| 699 | * |
||
| 700 | * @return INC22QueryRow |
||
| 701 | * @throws CircleNotFoundException |
||
| 702 | */ |
||
| 703 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
| 726 | |||
| 727 | |||
| 728 | /** |
||
| 729 | * @param Circle $circle |
||
| 730 | * |
||
| 731 | * @return bool |
||
| 732 | * @throws OwnerNotFoundException |
||
| 733 | */ |
||
| 734 | public function compareWith(Circle $circle): bool { |
||
| 755 | |||
| 756 | |||
| 757 | /** |
||
| 758 | * @param Circle $circle |
||
| 759 | * @param int $display |
||
| 760 | * |
||
| 761 | * @return array |
||
| 762 | */ |
||
| 763 | public static function getCircleFlags(Circle $circle, int $display = self::FLAGS_LONG): array { |
||
| 783 | |||
| 784 | } |
||
| 785 | |||
| 786 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.