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 | ||
| 74 | class Circle extends ManagedModel implements IDeserializable, INC21QueryRow, JsonSerializable { | ||
| 75 | |||
| 76 | |||
| 77 | use TArrayTools; | ||
| 78 | use TNC21Deserialize; | ||
| 79 | |||
| 80 | |||
| 81 | const TYPES_SHORT = 1; | ||
| 82 | const TYPES_LONG = 2; | ||
| 83 | |||
| 84 | |||
| 85 | // specific value | ||
| 86 | const CFG_CIRCLE = 0; // only for code readability. Circle is locked by default. | ||
| 87 | const CFG_SINGLE = 1; // Circle with only one single member. | ||
| 88 | const CFG_PERSONAL = 2; // Personal circle, only the owner can see it. | ||
| 89 | |||
| 90 | // bitwise | ||
| 91 | const CFG_SYSTEM = 4; // System Circl (not managed by the official front-end). Meaning some config are limited | ||
| 92 | const CFG_VISIBLE = 8; // Visible to everyone, if not visible, people have to know its name to be able to find it | ||
| 93 | const CFG_OPEN = 16; // Circle is open, people can join | ||
| 94 | const CFG_INVITE = 32; // Adding a member generate an invitation that needs to be accepted | ||
| 95 | const CFG_REQUEST = 64; // Request to join Circles needs to be confirmed by a moderator | ||
| 96 | const CFG_FRIEND = 128; // Members of the circle can invite their friends | ||
| 97 | const CFG_PROTECTED = 256; // Password protected to join/request | ||
| 98 | const CFG_NO_OWNER = 512; // no owner, only members | ||
| 99 | const CFG_HIDDEN = 1024; // hidden from listing, but available as a share entity | ||
| 100 | const CFG_BACKEND = 2048; // Fully hidden, only backend Circles | ||
| 101 | const CFG_ROOT = 4096; // Circle cannot be inside another Circle | ||
| 102 | const CFG_FEDERATED = 8192; // Federated | ||
| 103 | |||
| 104 | |||
| 105 | public static $DEF_CFG_MAX = 16383; | ||
| 106 | |||
| 107 | public static $DEF_CFG = [ | ||
| 108 | 1 => 'S|Single', | ||
| 109 | 2 => 'P|Personal', | ||
| 110 | 4 => 'Y|System', | ||
| 111 | 8 => 'V|Visible', | ||
| 112 | 16 => 'O|Open', | ||
| 113 | 32 => 'I|Invite', | ||
| 114 | 64 => 'JR|Join Request', | ||
| 115 | 128 => 'F|Friends', | ||
| 116 | 256 => 'PP|Password Protected', | ||
| 117 | 512 => 'NO|No Owner', | ||
| 118 | 1024 => 'H|Hidden', | ||
| 119 | 2048 => 'T|Backend', | ||
| 120 | 4096 => 'T|Root', | ||
| 121 | 8192 => 'F|Federated' | ||
| 122 | ]; | ||
| 123 | |||
| 124 | public static $DEF_CFG_CORE_FILTER = [ | ||
| 125 | 1, | ||
| 126 | 2, | ||
| 127 | 4 | ||
| 128 | ]; | ||
| 129 | |||
| 130 | public static $DEF_CFG_SYSTEM_FILTER = [ | ||
| 131 | 512, | ||
| 132 | 1024, | ||
| 133 | 2048, | ||
| 134 | 4096 | ||
| 135 | ]; | ||
| 136 | |||
| 137 | |||
| 138 | /** @var string */ | ||
| 139 | private $id = ''; | ||
| 140 | |||
| 141 | /** @var int */ | ||
| 142 | private $config = 0; | ||
| 143 | |||
| 144 | /** @var int */ | ||
| 145 | private $type = 0; | ||
| 146 | |||
| 147 | /** @var string */ | ||
| 148 | private $name = ''; | ||
| 149 | |||
| 150 | /** @var string */ | ||
| 151 | private $altName = ''; | ||
| 152 | |||
| 153 | /** @var Member */ | ||
| 154 | private $owner; | ||
| 155 | |||
| 156 | /** @var array */ | ||
| 157 | private $members = []; | ||
| 158 | |||
| 159 | /** @var Member */ | ||
| 160 | private $initiator; | ||
| 161 | |||
| 162 | /** @var array */ | ||
| 163 | private $settings = []; | ||
| 164 | |||
| 165 | /** @var string */ | ||
| 166 | private $description = ''; | ||
| 167 | |||
| 168 | /** @var int */ | ||
| 169 | private $contactAddressBook = 0; | ||
| 170 | |||
| 171 | /** @var string */ | ||
| 172 | private $contactGroupName = ''; | ||
| 173 | |||
| 174 | /** @var string */ | ||
| 175 | private $instance = ''; | ||
| 176 | |||
| 177 | // /** @var bool */ | ||
| 178 | // private $hidden = false; | ||
| 179 | |||
| 180 | /** @var int */ | ||
| 181 | private $creation = 0; | ||
| 182 | |||
| 183 | |||
| 184 | /** @var Circle[] */ | ||
| 185 | private $memberOf = null; | ||
| 186 | |||
| 187 | private $completeJson = false; | ||
| 188 | |||
| 189 | |||
| 190 | /** | ||
| 191 | * Circle constructor. | ||
| 192 | */ | ||
| 193 | 	public function __construct() { | ||
| 195 | |||
| 196 | /** | ||
| 197 | * @param string $id | ||
| 198 | * | ||
| 199 | * @return self | ||
| 200 | */ | ||
| 201 | 	public function setId(string $id): self { | ||
| 206 | |||
| 207 | /** | ||
| 208 | * @return string | ||
| 209 | */ | ||
| 210 | 	public function getId(): string { | ||
| 213 | |||
| 214 | |||
| 215 | /** | ||
| 216 | * @param int $config | ||
| 217 | * | ||
| 218 | * @return self | ||
| 219 | */ | ||
| 220 | 	public function setConfig(int $config): self { | ||
| 233 | |||
| 234 | /** | ||
| 235 | * @return int | ||
| 236 | */ | ||
| 237 | 	public function getConfig(): int { | ||
| 240 | |||
| 241 | /** | ||
| 242 | * @param int $flag | ||
| 243 | * @param int $test | ||
| 244 | * | ||
| 245 | * @return bool | ||
| 246 | */ | ||
| 247 | 	public function isConfig(int $flag, int $test = 0): bool { | ||
| 254 | |||
| 255 | /** | ||
| 256 | * @param int $flag | ||
| 257 | */ | ||
| 258 | 	public function addConfig(int $flag): void { | ||
| 263 | |||
| 264 | /** | ||
| 265 | * @param int $flag | ||
| 266 | */ | ||
| 267 | 	public function remConfig(int $flag): void { | ||
| 272 | |||
| 273 | |||
| 274 | /** | ||
| 275 | * @param string $name | ||
| 276 | * | ||
| 277 | * @return self | ||
| 278 | */ | ||
| 279 | 	public function setName(string $name): self { | ||
| 284 | |||
| 285 | /** | ||
| 286 | * @return string | ||
| 287 | */ | ||
| 288 | 	public function getName(): string { | ||
| 291 | |||
| 292 | |||
| 293 | /** | ||
| 294 | * @param string $altName | ||
| 295 | * | ||
| 296 | * @return self | ||
| 297 | */ | ||
| 298 | 	public function setAltName(string $altName): self { | ||
| 303 | |||
| 304 | /** | ||
| 305 | * @return string | ||
| 306 | */ | ||
| 307 | 	public function getAltName(): string { | ||
| 310 | |||
| 311 | |||
| 312 | /** | ||
| 313 | * @param Member $owner | ||
| 314 | * | ||
| 315 | * @return self | ||
| 316 | */ | ||
| 317 | 	public function setOwner(Member $owner): self { | ||
| 322 | |||
| 323 | /** | ||
| 324 | * @return Member | ||
| 325 | */ | ||
| 326 | 	public function getOwner(): Member { | ||
| 329 | |||
| 330 | /** | ||
| 331 | * @return bool | ||
| 332 | */ | ||
| 333 | 	public function hasOwner(): bool { | ||
| 336 | |||
| 337 | |||
| 338 | /** | ||
| 339 | * @param array $members | ||
| 340 | * | ||
| 341 | * @return self | ||
| 342 | */ | ||
| 343 | 	public function setMembers(array $members): self { | ||
| 348 | |||
| 349 | /** | ||
| 350 | * @return array | ||
| 351 | */ | ||
| 352 | 	public function getMembers(): array { | ||
| 359 | |||
| 360 | |||
| 361 | /** | ||
| 362 | * @param Member $initiator | ||
| 363 | * | ||
| 364 | * @return Circle | ||
| 365 | */ | ||
| 366 | 	public function setInitiator(Member $initiator): self { | ||
| 371 | |||
| 372 | /** | ||
| 373 | * @return Member | ||
| 374 | */ | ||
| 375 | 	public function getInitiator(): Member { | ||
| 378 | |||
| 379 | /** | ||
| 380 | * @return bool | ||
| 381 | */ | ||
| 382 | 	public function hasInitiator(): bool { | ||
| 385 | |||
| 386 | /** | ||
| 387 | * @param string $instance | ||
| 388 | * | ||
| 389 | * @return Circle | ||
| 390 | */ | ||
| 391 | 	public function setInstance(string $instance): self { | ||
| 398 | |||
| 399 | /** | ||
| 400 | * @return string | ||
| 401 | * @throws OwnerNotFoundException | ||
| 402 | */ | ||
| 403 | 	public function getInstance(): string { | ||
| 414 | |||
| 415 | |||
| 416 | /** | ||
| 417 | * @param array $settings | ||
| 418 | * | ||
| 419 | * @return self | ||
| 420 | */ | ||
| 421 | 	public function setSettings(array $settings): self { | ||
| 426 | |||
| 427 | /** | ||
| 428 | * @return array | ||
| 429 | */ | ||
| 430 | 	public function getSettings(): array { | ||
| 433 | |||
| 434 | |||
| 435 | /** | ||
| 436 | * @param string $description | ||
| 437 | * | ||
| 438 | * @return self | ||
| 439 | */ | ||
| 440 | 	public function setDescription(string $description): self { | ||
| 445 | |||
| 446 | /** | ||
| 447 | * @return string | ||
| 448 | */ | ||
| 449 | 	public function getDescription(): string { | ||
| 452 | |||
| 453 | |||
| 454 | /** | ||
| 455 | * @param int $contactAddressBook | ||
| 456 | * | ||
| 457 | * @return self | ||
| 458 | */ | ||
| 459 | 	public function setContactAddressBook(int $contactAddressBook): self { | ||
| 464 | |||
| 465 | /** | ||
| 466 | * @return int | ||
| 467 | */ | ||
| 468 | 	public function getContactAddressBook(): int { | ||
| 471 | |||
| 472 | |||
| 473 | /** | ||
| 474 | * @param string $contactGroupName | ||
| 475 | * | ||
| 476 | * @return self | ||
| 477 | */ | ||
| 478 | 	public function setContactGroupName(string $contactGroupName): self { | ||
| 483 | |||
| 484 | /** | ||
| 485 | * @return string | ||
| 486 | */ | ||
| 487 | 	public function getContactGroupName(): string { | ||
| 490 | |||
| 491 | |||
| 492 | // /** | ||
| 493 | // * @param bool $hidden | ||
| 494 | // * | ||
| 495 | // * @return Circle | ||
| 496 | // */ | ||
| 497 | //	public function setHidden(bool $hidden): self { | ||
| 498 | // $this->hidden = $hidden; | ||
| 499 | // | ||
| 500 | // return $this; | ||
| 501 | // } | ||
| 502 | // | ||
| 503 | // /** | ||
| 504 | // * @return bool | ||
| 505 | // */ | ||
| 506 | //	public function isHidden(): bool { | ||
| 507 | // return $this->hidden; | ||
| 508 | // } | ||
| 509 | |||
| 510 | |||
| 511 | /** | ||
| 512 | * @param array $memberOf | ||
| 513 | * | ||
| 514 | * @return $this | ||
| 515 | */ | ||
| 516 | 	public function setMemberOf(array $memberOf): self { | ||
| 521 | |||
| 522 | /** | ||
| 523 | * @return Circle[] | ||
| 524 | */ | ||
| 525 | 	public function memberOf(): array { | ||
| 532 | |||
| 533 | |||
| 534 | /** | ||
| 535 | * @param int $creation | ||
| 536 | * | ||
| 537 | * @return self | ||
| 538 | */ | ||
| 539 | 	public function setCreation(int $creation): self { | ||
| 544 | |||
| 545 | /** | ||
| 546 | * @return int | ||
| 547 | */ | ||
| 548 | 	public function getCreation(): int { | ||
| 551 | |||
| 552 | |||
| 553 | /** | ||
| 554 | * @param array $data | ||
| 555 | * | ||
| 556 | * @return $this | ||
| 557 | * @throws InvalidItemException | ||
| 558 | */ | ||
| 559 | 	public function import(array $data): IDeserializable { | ||
| 591 | |||
| 592 | |||
| 593 | /** | ||
| 594 | * @return array | ||
| 595 | */ | ||
| 596 | 	public function jsonSerialize(): array { | ||
| 622 | |||
| 623 | |||
| 624 | /** | ||
| 625 | * @param array $data | ||
| 626 | * @param string $prefix | ||
| 627 | * | ||
| 628 | * @return INC21QueryRow | ||
| 629 | * @throws CircleNotFoundException | ||
| 630 | */ | ||
| 631 | 	public function importFromDatabase(array $data, string $prefix = ''): INC21QueryRow { | ||
| 654 | |||
| 655 | |||
| 656 | /** | ||
| 657 | * @param Circle $circle | ||
| 658 | * | ||
| 659 | * @return bool | ||
| 660 | * @throws OwnerNotFoundException | ||
| 661 | */ | ||
| 662 | 	public function compareWith(Circle $circle): bool { | ||
| 683 | |||
| 684 | |||
| 685 | /** | ||
| 686 | * @param Circle $circle | ||
| 687 | * @param int $display | ||
| 688 | * | ||
| 689 | * @return array | ||
| 690 | */ | ||
| 691 | 	public static function getCircleTypes(Circle $circle, int $display = self::TYPES_LONG): array { | ||
| 711 | |||
| 712 | } | ||
| 713 | |||
| 714 |