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 | 65536 => 'M|Nountpoint' |
||
135 | ]; |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Note: When editing those values, update lib/Application/Capabilities.php |
||
140 | * |
||
141 | * @see Capabilities::getCapabilitiesCircleConstants() |
||
142 | * @var array |
||
143 | */ |
||
144 | public static $DEF_SOURCE = [ |
||
145 | 1 => 'Nextcloud User', |
||
146 | 2 => 'Nextcloud Group', |
||
147 | 4 => 'Mail Address', |
||
148 | 8 => 'Contact', |
||
149 | 16 => 'Circle', |
||
150 | 10001 => 'Circles App' |
||
151 | ]; |
||
152 | |||
153 | |||
154 | public static $DEF_CFG_CORE_FILTER = [ |
||
155 | 1, |
||
156 | 2, |
||
157 | 4 |
||
158 | ]; |
||
159 | |||
160 | public static $DEF_CFG_SYSTEM_FILTER = [ |
||
161 | 512, |
||
162 | 1024, |
||
163 | 2048 |
||
164 | ]; |
||
165 | |||
166 | |||
167 | /** @var string */ |
||
168 | private $singleId = ''; |
||
169 | |||
170 | /** @var int */ |
||
171 | private $config = 0; |
||
172 | |||
173 | /** @var string */ |
||
174 | private $name = ''; |
||
175 | |||
176 | /** @var string */ |
||
177 | private $displayName = ''; |
||
178 | |||
179 | /** @var int */ |
||
180 | private $source = 0; |
||
181 | |||
182 | /** @var Member */ |
||
183 | private $owner; |
||
184 | |||
185 | /** @var Member */ |
||
186 | private $initiator; |
||
187 | |||
188 | /** @var array */ |
||
189 | private $settings = []; |
||
190 | |||
191 | /** @var string */ |
||
192 | private $description = ''; |
||
193 | |||
194 | /** @var int */ |
||
195 | private $contactAddressBook = 0; |
||
196 | |||
197 | /** @var string */ |
||
198 | private $contactGroupName = ''; |
||
199 | |||
200 | /** @var string */ |
||
201 | private $instance = ''; |
||
202 | |||
203 | // /** @var bool */ |
||
204 | // private $hidden = false; |
||
205 | |||
206 | /** @var int */ |
||
207 | private $creation = 0; |
||
208 | |||
209 | |||
210 | /** @var Member[] */ |
||
211 | private $members = null; |
||
212 | |||
213 | /** @var Member[] */ |
||
214 | private $inheritedMembers = null; |
||
215 | |||
216 | /** @var bool */ |
||
217 | private $detailedInheritedMember = false; |
||
218 | |||
219 | /** @var Membership[] */ |
||
220 | private $memberships = null; |
||
221 | |||
222 | |||
223 | /** |
||
224 | * Circle constructor. |
||
225 | */ |
||
226 | public function __construct() { |
||
228 | |||
229 | /** |
||
230 | * @param string $singleId |
||
231 | * |
||
232 | * @return self |
||
233 | */ |
||
234 | public function setSingleId(string $singleId): self { |
||
239 | |||
240 | /** |
||
241 | * @return string |
||
242 | */ |
||
243 | public function getSingleId(): string { |
||
246 | |||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | * @deprecated - removed in NC23 |
||
251 | */ |
||
252 | public function getUniqueId(): string { |
||
255 | |||
256 | |||
257 | /** |
||
258 | * @param int $config |
||
259 | * |
||
260 | * @return self |
||
261 | */ |
||
262 | public function setConfig(int $config): self { |
||
267 | |||
268 | /** |
||
269 | * @return int |
||
270 | */ |
||
271 | public function getConfig(): int { |
||
274 | |||
275 | /** |
||
276 | * @param int $flag |
||
277 | * @param int $test |
||
278 | * |
||
279 | * @return bool |
||
280 | */ |
||
281 | public function isConfig(int $flag, int $test = 0): bool { |
||
288 | |||
289 | /** |
||
290 | * @param int $flag |
||
291 | */ |
||
292 | public function addConfig(int $flag): void { |
||
297 | |||
298 | /** |
||
299 | * @param int $flag |
||
300 | */ |
||
301 | public function remConfig(int $flag): void { |
||
306 | |||
307 | |||
308 | /** |
||
309 | * @param string $name |
||
310 | * |
||
311 | * @return self |
||
312 | */ |
||
313 | public function setName(string $name): self { |
||
321 | |||
322 | /** |
||
323 | * @return string |
||
324 | */ |
||
325 | public function getName(): string { |
||
328 | |||
329 | |||
330 | /** |
||
331 | * @param string $displayName |
||
332 | * |
||
333 | * @return self |
||
334 | */ |
||
335 | public function setDisplayName(string $displayName): self { |
||
342 | |||
343 | /** |
||
344 | * @return string |
||
345 | */ |
||
346 | public function getDisplayName(): string { |
||
349 | |||
350 | |||
351 | /** |
||
352 | * @param int $source |
||
353 | * |
||
354 | * @return Circle |
||
355 | */ |
||
356 | public function setSource(int $source): self { |
||
361 | |||
362 | /** |
||
363 | * @return int |
||
364 | */ |
||
365 | public function getSource(): int { |
||
368 | |||
369 | |||
370 | /** |
||
371 | * @param ?Member $owner |
||
|
|||
372 | * |
||
373 | * @return self |
||
374 | */ |
||
375 | public function setOwner(?Member $owner): self { |
||
380 | |||
381 | /** |
||
382 | * @return Member |
||
383 | */ |
||
384 | public function getOwner(): Member { |
||
387 | |||
388 | /** |
||
389 | * @return bool |
||
390 | */ |
||
391 | public function hasOwner(): bool { |
||
394 | |||
395 | |||
396 | /** |
||
397 | * @return bool |
||
398 | */ |
||
399 | public function hasMembers(): bool { |
||
402 | |||
403 | /** |
||
404 | * @param array $members |
||
405 | * |
||
406 | * @return self |
||
407 | */ |
||
408 | public function setMembers(array $members): IMemberships { |
||
413 | |||
414 | /** |
||
415 | * @return array |
||
416 | */ |
||
417 | public function getMembers(): array { |
||
424 | |||
425 | |||
426 | /** |
||
427 | * @param array $members |
||
428 | * @param bool $detailed |
||
429 | * |
||
430 | * @return self |
||
431 | */ |
||
432 | public function setInheritedMembers(array $members, bool $detailed): IMemberships { |
||
438 | |||
439 | /** |
||
440 | * @param bool $detailed |
||
441 | * |
||
442 | * @return array |
||
443 | */ |
||
444 | public function getInheritedMembers(bool $detailed = false): array { |
||
452 | |||
453 | |||
454 | /** |
||
455 | * @return bool |
||
456 | */ |
||
457 | public function hasMemberships(): bool { |
||
460 | |||
461 | /** |
||
462 | * @param array $memberships |
||
463 | * |
||
464 | * @return self |
||
465 | */ |
||
466 | public function setMemberships(array $memberships): IMemberships { |
||
471 | |||
472 | /** |
||
473 | * @return Membership[] |
||
474 | */ |
||
475 | public function getMemberships(): array { |
||
482 | |||
483 | |||
484 | /** |
||
485 | * @param Member|null $initiator |
||
486 | * |
||
487 | * @return Circle |
||
488 | */ |
||
489 | public function setInitiator(?Member $initiator): self { |
||
494 | |||
495 | /** |
||
496 | * @return Member |
||
497 | */ |
||
498 | public function getInitiator(): Member { |
||
501 | |||
502 | /** |
||
503 | * @return bool |
||
504 | */ |
||
505 | public function hasInitiator(): bool { |
||
508 | |||
509 | /** |
||
510 | * @param string $instance |
||
511 | * |
||
512 | * @return Circle |
||
513 | */ |
||
514 | public function setInstance(string $instance): self { |
||
521 | |||
522 | /** |
||
523 | * @return string |
||
524 | * @throws OwnerNotFoundException |
||
525 | */ |
||
526 | public function getInstance(): string { |
||
533 | |||
534 | |||
535 | /** |
||
536 | * @param array $settings |
||
537 | * |
||
538 | * @return self |
||
539 | */ |
||
540 | public function setSettings(array $settings): self { |
||
545 | |||
546 | /** |
||
547 | * @return array |
||
548 | */ |
||
549 | public function getSettings(): array { |
||
552 | |||
553 | |||
554 | /** |
||
555 | * @param string $description |
||
556 | * |
||
557 | * @return self |
||
558 | */ |
||
559 | public function setDescription(string $description): self { |
||
564 | |||
565 | /** |
||
566 | * @return string |
||
567 | */ |
||
568 | public function getDescription(): string { |
||
571 | |||
572 | |||
573 | /** |
||
574 | * @return string |
||
575 | */ |
||
576 | public function getUrl(): string { |
||
579 | |||
580 | |||
581 | /** |
||
582 | * @param int $contactAddressBook |
||
583 | * |
||
584 | * @return self |
||
585 | */ |
||
586 | public function setContactAddressBook(int $contactAddressBook): self { |
||
591 | |||
592 | /** |
||
593 | * @return int |
||
594 | */ |
||
595 | public function getContactAddressBook(): int { |
||
598 | |||
599 | |||
600 | /** |
||
601 | * @param string $contactGroupName |
||
602 | * |
||
603 | * @return self |
||
604 | */ |
||
605 | public function setContactGroupName(string $contactGroupName): self { |
||
610 | |||
611 | /** |
||
612 | * @return string |
||
613 | */ |
||
614 | public function getContactGroupName(): string { |
||
617 | |||
618 | |||
619 | /** |
||
620 | * @param int $creation |
||
621 | * |
||
622 | * @return self |
||
623 | */ |
||
624 | public function setCreation(int $creation): self { |
||
629 | |||
630 | /** |
||
631 | * @return int |
||
632 | */ |
||
633 | public function getCreation(): int { |
||
636 | |||
637 | |||
638 | /** |
||
639 | * @param array $data |
||
640 | * |
||
641 | * @return $this |
||
642 | * @throws InvalidItemException |
||
643 | */ |
||
644 | public function import(array $data): IDeserializable { |
||
676 | |||
677 | |||
678 | /** |
||
679 | * @return array |
||
680 | */ |
||
681 | public function jsonSerialize(): array { |
||
713 | |||
714 | |||
715 | /** |
||
716 | * @param array $data |
||
717 | * @param string $prefix |
||
718 | * |
||
719 | * @return INC22QueryRow |
||
720 | * @throws CircleNotFoundException |
||
721 | */ |
||
722 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
745 | |||
746 | |||
747 | /** |
||
748 | * @param Circle $circle |
||
749 | * |
||
750 | * @return bool |
||
751 | * @throws OwnerNotFoundException |
||
752 | */ |
||
753 | public function compareWith(Circle $circle): bool { |
||
774 | |||
775 | |||
776 | /** |
||
777 | * @param Circle $circle |
||
778 | * @param int $display |
||
779 | * |
||
780 | * @return array |
||
781 | */ |
||
782 | public static function getCircleFlags(Circle $circle, int $display = self::FLAGS_LONG): array { |
||
802 | |||
803 | } |
||
804 | |||
805 |
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.