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 Circle[] */ |
||
210 | private $memberOf = null; |
||
211 | |||
212 | /** @var Member[] */ |
||
213 | private $members = null; |
||
214 | |||
215 | /** @var Member[] */ |
||
216 | private $inheritedMembers = null; |
||
217 | |||
218 | /** @var bool */ |
||
219 | private $detailedInheritedMember = false; |
||
220 | |||
221 | /** @var Membership[] */ |
||
222 | private $memberships = null; |
||
223 | |||
224 | |||
225 | /** |
||
226 | * Circle constructor. |
||
227 | */ |
||
228 | public function __construct() { |
||
230 | |||
231 | /** |
||
232 | * @param string $singleId |
||
233 | * |
||
234 | * @return self |
||
235 | */ |
||
236 | public function setSingleId(string $singleId): self { |
||
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | public function getSingleId(): string { |
||
248 | |||
249 | |||
250 | /** |
||
251 | * @param int $config |
||
252 | * |
||
253 | * @return self |
||
254 | */ |
||
255 | public function setConfig(int $config): self { |
||
260 | |||
261 | /** |
||
262 | * @return int |
||
263 | */ |
||
264 | public function getConfig(): int { |
||
267 | |||
268 | /** |
||
269 | * @param int $flag |
||
270 | * @param int $test |
||
271 | * |
||
272 | * @return bool |
||
273 | */ |
||
274 | public function isConfig(int $flag, int $test = 0): bool { |
||
281 | |||
282 | /** |
||
283 | * @param int $flag |
||
284 | */ |
||
285 | public function addConfig(int $flag): void { |
||
290 | |||
291 | /** |
||
292 | * @param int $flag |
||
293 | */ |
||
294 | public function remConfig(int $flag): void { |
||
299 | |||
300 | |||
301 | /** |
||
302 | * @param string $name |
||
303 | * |
||
304 | * @return self |
||
305 | */ |
||
306 | public function setName(string $name): self { |
||
314 | |||
315 | /** |
||
316 | * @return string |
||
317 | */ |
||
318 | public function getName(): string { |
||
321 | |||
322 | |||
323 | /** |
||
324 | * @param string $displayName |
||
325 | * |
||
326 | * @return self |
||
327 | */ |
||
328 | public function setDisplayName(string $displayName): self { |
||
335 | |||
336 | /** |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getDisplayName(): string { |
||
342 | |||
343 | |||
344 | /** |
||
345 | * @param int $source |
||
346 | * |
||
347 | * @return Circle |
||
348 | */ |
||
349 | public function setSource(int $source): self { |
||
354 | |||
355 | /** |
||
356 | * @return int |
||
357 | */ |
||
358 | public function getSource(): int { |
||
361 | |||
362 | |||
363 | /** |
||
364 | * @param ?Member $owner |
||
|
|||
365 | * |
||
366 | * @return self |
||
367 | */ |
||
368 | public function setOwner(?Member $owner): self { |
||
373 | |||
374 | /** |
||
375 | * @return Member |
||
376 | */ |
||
377 | public function getOwner(): Member { |
||
380 | |||
381 | /** |
||
382 | * @return bool |
||
383 | */ |
||
384 | public function hasOwner(): bool { |
||
387 | |||
388 | |||
389 | /** |
||
390 | * @param array $members |
||
391 | * |
||
392 | * @return self |
||
393 | */ |
||
394 | public function setMembers(array $members): IMemberships { |
||
399 | |||
400 | /** |
||
401 | * @return array |
||
402 | */ |
||
403 | public function getMembers(): array { |
||
410 | |||
411 | |||
412 | /** |
||
413 | * @param array $members |
||
414 | * @param bool $detailed |
||
415 | * |
||
416 | * @return self |
||
417 | */ |
||
418 | public function setInheritedMembers(array $members, bool $detailed): IMemberships { |
||
424 | |||
425 | /** |
||
426 | * @param bool $detailed |
||
427 | * |
||
428 | * @return array |
||
429 | */ |
||
430 | public function getInheritedMembers(bool $detailed = false): array { |
||
438 | |||
439 | |||
440 | /** |
||
441 | * @param array $memberships |
||
442 | * |
||
443 | * @return self |
||
444 | */ |
||
445 | public function setMemberships(array $memberships): IMemberships { |
||
450 | |||
451 | /** |
||
452 | * @return Membership[] |
||
453 | */ |
||
454 | public function getMemberships(): array { |
||
461 | |||
462 | |||
463 | /** |
||
464 | * @param Member|null $initiator |
||
465 | * |
||
466 | * @return Circle |
||
467 | */ |
||
468 | public function setInitiator(?Member $initiator): self { |
||
473 | |||
474 | /** |
||
475 | * @return Member |
||
476 | */ |
||
477 | public function getInitiator(): Member { |
||
480 | |||
481 | /** |
||
482 | * @return bool |
||
483 | */ |
||
484 | public function hasInitiator(): bool { |
||
487 | |||
488 | /** |
||
489 | * @param string $instance |
||
490 | * |
||
491 | * @return Circle |
||
492 | */ |
||
493 | public function setInstance(string $instance): self { |
||
500 | |||
501 | /** |
||
502 | * @return string |
||
503 | * @throws OwnerNotFoundException |
||
504 | */ |
||
505 | public function getInstance(): string { |
||
512 | |||
513 | |||
514 | /** |
||
515 | * @param array $settings |
||
516 | * |
||
517 | * @return self |
||
518 | */ |
||
519 | public function setSettings(array $settings): self { |
||
524 | |||
525 | /** |
||
526 | * @return array |
||
527 | */ |
||
528 | public function getSettings(): array { |
||
531 | |||
532 | |||
533 | /** |
||
534 | * @param string $description |
||
535 | * |
||
536 | * @return self |
||
537 | */ |
||
538 | public function setDescription(string $description): self { |
||
543 | |||
544 | /** |
||
545 | * @return string |
||
546 | */ |
||
547 | public function getDescription(): string { |
||
550 | |||
551 | |||
552 | /** |
||
553 | * @param int $contactAddressBook |
||
554 | * |
||
555 | * @return self |
||
556 | */ |
||
557 | public function setContactAddressBook(int $contactAddressBook): self { |
||
562 | |||
563 | /** |
||
564 | * @return int |
||
565 | */ |
||
566 | public function getContactAddressBook(): int { |
||
569 | |||
570 | |||
571 | /** |
||
572 | * @param string $contactGroupName |
||
573 | * |
||
574 | * @return self |
||
575 | */ |
||
576 | public function setContactGroupName(string $contactGroupName): self { |
||
581 | |||
582 | /** |
||
583 | * @return string |
||
584 | */ |
||
585 | public function getContactGroupName(): string { |
||
588 | |||
589 | |||
590 | /** |
||
591 | * @param array $memberOf |
||
592 | * |
||
593 | * @return $this |
||
594 | */ |
||
595 | public function setMemberOf(array $memberOf): self { |
||
600 | |||
601 | /** |
||
602 | * @return Circle[] |
||
603 | */ |
||
604 | public function memberOf(): array { |
||
611 | |||
612 | |||
613 | /** |
||
614 | * @param int $creation |
||
615 | * |
||
616 | * @return self |
||
617 | */ |
||
618 | public function setCreation(int $creation): self { |
||
623 | |||
624 | /** |
||
625 | * @return int |
||
626 | */ |
||
627 | public function getCreation(): int { |
||
630 | |||
631 | |||
632 | /** |
||
633 | * @param array $data |
||
634 | * |
||
635 | * @return $this |
||
636 | * @throws InvalidItemException |
||
637 | */ |
||
638 | public function import(array $data): IDeserializable { |
||
670 | |||
671 | |||
672 | /** |
||
673 | * @return array |
||
674 | */ |
||
675 | public function jsonSerialize(): array { |
||
710 | |||
711 | |||
712 | /** |
||
713 | * @param array $data |
||
714 | * @param string $prefix |
||
715 | * |
||
716 | * @return INC22QueryRow |
||
717 | * @throws CircleNotFoundException |
||
718 | */ |
||
719 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
742 | |||
743 | |||
744 | /** |
||
745 | * @param Circle $circle |
||
746 | * |
||
747 | * @return bool |
||
748 | * @throws OwnerNotFoundException |
||
749 | */ |
||
750 | public function compareWith(Circle $circle): bool { |
||
771 | |||
772 | |||
773 | /** |
||
774 | * @param Circle $circle |
||
775 | * @param int $display |
||
776 | * |
||
777 | * @return array |
||
778 | */ |
||
779 | public static function getCircleFlags(Circle $circle, int $display = self::FLAGS_LONG): array { |
||
799 | |||
800 | } |
||
801 | |||
802 |
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.