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 | 10002 => 'occ Command Line' |
||
152 | ]; |
||
153 | |||
154 | |||
155 | public static $DEF_CFG_CORE_FILTER = [ |
||
156 | 1, |
||
157 | 2, |
||
158 | 4 |
||
159 | ]; |
||
160 | |||
161 | public static $DEF_CFG_SYSTEM_FILTER = [ |
||
162 | 512, |
||
163 | 1024, |
||
164 | 2048 |
||
165 | ]; |
||
166 | |||
167 | |||
168 | /** @var string */ |
||
169 | private $singleId = ''; |
||
170 | |||
171 | /** @var int */ |
||
172 | private $config = 0; |
||
173 | |||
174 | /** @var string */ |
||
175 | private $name = ''; |
||
176 | |||
177 | /** @var string */ |
||
178 | private $displayName = ''; |
||
179 | |||
180 | /** @var int */ |
||
181 | private $source = 0; |
||
182 | |||
183 | /** @var Member */ |
||
184 | private $owner; |
||
185 | |||
186 | /** @var Member */ |
||
187 | private $initiator; |
||
188 | |||
189 | /** @var array */ |
||
190 | private $settings = []; |
||
191 | |||
192 | /** @var string */ |
||
193 | private $description = ''; |
||
194 | |||
195 | /** @var int */ |
||
196 | private $contactAddressBook = 0; |
||
197 | |||
198 | /** @var string */ |
||
199 | private $contactGroupName = ''; |
||
200 | |||
201 | /** @var string */ |
||
202 | private $instance = ''; |
||
203 | |||
204 | // /** @var bool */ |
||
205 | // private $hidden = false; |
||
206 | |||
207 | /** @var int */ |
||
208 | private $creation = 0; |
||
209 | |||
210 | |||
211 | /** @var Member[] */ |
||
212 | private $members = null; |
||
213 | |||
214 | /** @var Member[] */ |
||
215 | private $inheritedMembers = null; |
||
216 | |||
217 | /** @var bool */ |
||
218 | private $detailedInheritedMember = false; |
||
219 | |||
220 | /** @var Membership[] */ |
||
221 | private $memberships = null; |
||
222 | |||
223 | |||
224 | /** |
||
225 | * Circle constructor. |
||
226 | */ |
||
227 | public function __construct() { |
||
229 | |||
230 | /** |
||
231 | * @param string $singleId |
||
232 | * |
||
233 | * @return self |
||
234 | */ |
||
235 | public function setSingleId(string $singleId): self { |
||
240 | |||
241 | /** |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getSingleId(): string { |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | * @deprecated - removed in NC23 |
||
251 | */ |
||
252 | public function getUniqueId(): string { |
||
255 | |||
256 | /** |
||
257 | * @param int $config |
||
258 | * |
||
259 | * @return self |
||
260 | */ |
||
261 | public function setConfig(int $config): self { |
||
266 | |||
267 | /** |
||
268 | * @return int |
||
269 | */ |
||
270 | public function getConfig(): int { |
||
273 | |||
274 | /** |
||
275 | * @param int $flag |
||
276 | * @param int $test |
||
277 | * |
||
278 | * @return bool |
||
279 | */ |
||
280 | public function isConfig(int $flag, int $test = 0): bool { |
||
287 | |||
288 | /** |
||
289 | * @param int $flag |
||
290 | */ |
||
291 | public function addConfig(int $flag): void { |
||
296 | |||
297 | /** |
||
298 | * @param int $flag |
||
299 | */ |
||
300 | public function remConfig(int $flag): void { |
||
305 | |||
306 | |||
307 | /** |
||
308 | * @param string $name |
||
309 | * |
||
310 | * @return self |
||
311 | */ |
||
312 | public function setName(string $name): self { |
||
320 | |||
321 | /** |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getName(): string { |
||
327 | |||
328 | |||
329 | /** |
||
330 | * @param string $displayName |
||
331 | * |
||
332 | * @return self |
||
333 | */ |
||
334 | public function setDisplayName(string $displayName): self { |
||
341 | |||
342 | /** |
||
343 | * @return string |
||
344 | */ |
||
345 | public function getDisplayName(): string { |
||
348 | |||
349 | |||
350 | /** |
||
351 | * @param int $source |
||
352 | * |
||
353 | * @return Circle |
||
354 | */ |
||
355 | public function setSource(int $source): self { |
||
360 | |||
361 | /** |
||
362 | * @return int |
||
363 | */ |
||
364 | public function getSource(): int { |
||
367 | |||
368 | |||
369 | /** |
||
370 | * @param ?Member $owner |
||
|
|||
371 | * |
||
372 | * @return self |
||
373 | */ |
||
374 | public function setOwner(?Member $owner): self { |
||
379 | |||
380 | /** |
||
381 | * @return Member |
||
382 | */ |
||
383 | public function getOwner(): Member { |
||
386 | |||
387 | /** |
||
388 | * @return bool |
||
389 | */ |
||
390 | public function hasOwner(): bool { |
||
393 | |||
394 | |||
395 | /** |
||
396 | * @return bool |
||
397 | */ |
||
398 | public function hasMembers(): bool { |
||
401 | |||
402 | /** |
||
403 | * @param array $members |
||
404 | * |
||
405 | * @return self |
||
406 | */ |
||
407 | public function setMembers(array $members): IMemberships { |
||
412 | |||
413 | /** |
||
414 | * @return array |
||
415 | */ |
||
416 | public function getMembers(): array { |
||
423 | |||
424 | |||
425 | /** |
||
426 | * @param array $members |
||
427 | * @param bool $detailed |
||
428 | * |
||
429 | * @return self |
||
430 | */ |
||
431 | public function setInheritedMembers(array $members, bool $detailed): IMemberships { |
||
437 | |||
438 | /** |
||
439 | * @param bool $detailed |
||
440 | * |
||
441 | * @return Member[] |
||
442 | */ |
||
443 | public function getInheritedMembers(bool $detailed = false): array { |
||
451 | |||
452 | |||
453 | /** |
||
454 | * @return bool |
||
455 | */ |
||
456 | public function hasMemberships(): bool { |
||
459 | |||
460 | /** |
||
461 | * @param array $memberships |
||
462 | * |
||
463 | * @return self |
||
464 | */ |
||
465 | public function setMemberships(array $memberships): IMemberships { |
||
470 | |||
471 | /** |
||
472 | * @return Membership[] |
||
473 | */ |
||
474 | public function getMemberships(): array { |
||
481 | |||
482 | |||
483 | /** |
||
484 | * @param Member|null $initiator |
||
485 | * |
||
486 | * @return Circle |
||
487 | */ |
||
488 | public function setInitiator(?Member $initiator): self { |
||
493 | |||
494 | /** |
||
495 | * @return Member |
||
496 | */ |
||
497 | public function getInitiator(): Member { |
||
500 | |||
501 | /** |
||
502 | * @return bool |
||
503 | */ |
||
504 | public function hasInitiator(): bool { |
||
507 | |||
508 | /** |
||
509 | * @param string $instance |
||
510 | * |
||
511 | * @return Circle |
||
512 | */ |
||
513 | public function setInstance(string $instance): self { |
||
520 | |||
521 | /** |
||
522 | * @return string |
||
523 | * @throws OwnerNotFoundException |
||
524 | */ |
||
525 | public function getInstance(): string { |
||
532 | |||
533 | |||
534 | /** |
||
535 | * @param array $settings |
||
536 | * |
||
537 | * @return self |
||
538 | */ |
||
539 | public function setSettings(array $settings): self { |
||
544 | |||
545 | /** |
||
546 | * @return array |
||
547 | */ |
||
548 | public function getSettings(): array { |
||
551 | |||
552 | |||
553 | /** |
||
554 | * @param string $description |
||
555 | * |
||
556 | * @return self |
||
557 | */ |
||
558 | public function setDescription(string $description): self { |
||
563 | |||
564 | /** |
||
565 | * @return string |
||
566 | */ |
||
567 | public function getDescription(): string { |
||
570 | |||
571 | |||
572 | /** |
||
573 | * @return string |
||
574 | */ |
||
575 | public function getUrl(): string { |
||
578 | |||
579 | |||
580 | /** |
||
581 | * @param int $contactAddressBook |
||
582 | * |
||
583 | * @return self |
||
584 | */ |
||
585 | public function setContactAddressBook(int $contactAddressBook): self { |
||
590 | |||
591 | /** |
||
592 | * @return int |
||
593 | */ |
||
594 | public function getContactAddressBook(): int { |
||
597 | |||
598 | |||
599 | /** |
||
600 | * @param string $contactGroupName |
||
601 | * |
||
602 | * @return self |
||
603 | */ |
||
604 | public function setContactGroupName(string $contactGroupName): self { |
||
609 | |||
610 | /** |
||
611 | * @return string |
||
612 | */ |
||
613 | public function getContactGroupName(): string { |
||
616 | |||
617 | |||
618 | /** |
||
619 | * @param int $creation |
||
620 | * |
||
621 | * @return self |
||
622 | */ |
||
623 | public function setCreation(int $creation): self { |
||
628 | |||
629 | /** |
||
630 | * @return int |
||
631 | */ |
||
632 | public function getCreation(): int { |
||
635 | |||
636 | |||
637 | /** |
||
638 | * @param array $data |
||
639 | * |
||
640 | * @return $this |
||
641 | * @throws InvalidItemException |
||
642 | */ |
||
643 | public function import(array $data): IDeserializable { |
||
675 | |||
676 | |||
677 | /** |
||
678 | * @return array |
||
679 | */ |
||
680 | public function jsonSerialize(): array { |
||
712 | |||
713 | |||
714 | /** |
||
715 | * @param array $data |
||
716 | * @param string $prefix |
||
717 | * |
||
718 | * @return INC22QueryRow |
||
719 | * @throws CircleNotFoundException |
||
720 | */ |
||
721 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
744 | |||
745 | |||
746 | /** |
||
747 | * @param Circle $circle |
||
748 | * |
||
749 | * @return bool |
||
750 | * @throws OwnerNotFoundException |
||
751 | */ |
||
752 | public function compareWith(Circle $circle): bool { |
||
773 | |||
774 | |||
775 | /** |
||
776 | * @param Circle $circle |
||
777 | * @param int $display |
||
778 | * |
||
779 | * @return array |
||
780 | */ |
||
781 | public static function getCircleFlags(Circle $circle, int $display = self::FLAGS_LONG): array { |
||
801 | |||
802 | } |
||
803 | |||
804 |
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.