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 => 'Email Address', |
||
148 | 8 => 'Contact', |
||
149 | 16 => 'Circle', |
||
150 | 10001 => 'Circles App', |
||
151 | 10002 => 'Admin 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 string */ |
||
181 | private $sanitizedName = ''; |
||
182 | |||
183 | /** @var int */ |
||
184 | private $source = 0; |
||
185 | |||
186 | /** @var Member */ |
||
187 | private $owner; |
||
188 | |||
189 | /** @var Member */ |
||
190 | private $initiator; |
||
191 | |||
192 | /** @var array */ |
||
193 | private $settings = []; |
||
194 | |||
195 | /** @var string */ |
||
196 | private $description = ''; |
||
197 | |||
198 | /** @var int */ |
||
199 | private $contactAddressBook = 0; |
||
200 | |||
201 | /** @var string */ |
||
202 | private $contactGroupName = ''; |
||
203 | |||
204 | /** @var string */ |
||
205 | private $instance = ''; |
||
206 | |||
207 | /** @var int */ |
||
208 | private $population = 0; |
||
209 | |||
210 | // /** @var bool */ |
||
211 | // private $hidden = false; |
||
212 | |||
213 | /** @var int */ |
||
214 | private $creation = 0; |
||
215 | |||
216 | |||
217 | /** @var Member[] */ |
||
218 | private $members = null; |
||
219 | |||
220 | /** @var Member[] */ |
||
221 | private $inheritedMembers = null; |
||
222 | |||
223 | /** @var bool */ |
||
224 | private $detailedInheritedMember = false; |
||
225 | |||
226 | /** @var Membership[] */ |
||
227 | private $memberships = null; |
||
228 | |||
229 | |||
230 | /** |
||
231 | * Circle constructor. |
||
232 | */ |
||
233 | public function __construct() { |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @param string $singleId |
||
238 | * |
||
239 | * @return self |
||
240 | */ |
||
241 | public function setSingleId(string $singleId): self { |
||
242 | $this->singleId = $singleId; |
||
243 | |||
244 | return $this; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @return string |
||
249 | */ |
||
250 | public function getSingleId(): string { |
||
251 | return $this->singleId; |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | * @deprecated - removed in NC23 |
||
257 | */ |
||
258 | public function getUniqueId(): string { |
||
259 | return $this->getSingleId(); |
||
260 | } |
||
261 | |||
262 | |||
263 | /** |
||
264 | * @param int $config |
||
265 | * |
||
266 | * @return self |
||
267 | */ |
||
268 | public function setConfig(int $config): self { |
||
269 | $this->config = $config; |
||
270 | |||
271 | return $this; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @return int |
||
276 | */ |
||
277 | public function getConfig(): int { |
||
278 | return $this->config; |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * @param int $flag |
||
283 | * @param int $test |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function isConfig(int $flag, int $test = 0): bool { |
||
288 | if ($test === 0) { |
||
289 | $test = $this->getConfig(); |
||
290 | } |
||
291 | |||
292 | return (($test & $flag) !== 0); |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @param int $flag |
||
297 | */ |
||
298 | public function addConfig(int $flag): void { |
||
299 | if (!$this->isConfig($flag)) { |
||
300 | $this->config += $flag; |
||
301 | } |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * @param int $flag |
||
306 | */ |
||
307 | public function remConfig(int $flag): void { |
||
308 | if ($this->isConfig($flag)) { |
||
309 | $this->config -= $flag; |
||
310 | } |
||
311 | } |
||
312 | |||
313 | |||
314 | /** |
||
315 | * @param string $name |
||
316 | * |
||
317 | * @return self |
||
318 | */ |
||
319 | public function setName(string $name): self { |
||
320 | $this->name = $name; |
||
321 | |||
322 | return $this; |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * @return string |
||
327 | */ |
||
328 | public function getName(): string { |
||
329 | return $this->name; |
||
330 | } |
||
331 | |||
332 | |||
333 | /** |
||
334 | * @param string $displayName |
||
335 | * |
||
336 | * @return self |
||
337 | */ |
||
338 | public function setDisplayName(string $displayName): self { |
||
339 | $this->displayName = $displayName; |
||
340 | |||
341 | return $this; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @return string |
||
346 | */ |
||
347 | public function getDisplayName(): string { |
||
350 | |||
351 | |||
352 | /** |
||
353 | * @param string $sanitizedName |
||
354 | * |
||
355 | * @return Circle |
||
356 | */ |
||
357 | public function setSanitizedName(string $sanitizedName): self { |
||
362 | |||
363 | /** |
||
364 | * @return string |
||
365 | */ |
||
366 | public function getSanitizedName(): string { |
||
369 | |||
370 | |||
371 | /** |
||
372 | * @param int $source |
||
373 | * |
||
374 | * @return Circle |
||
375 | */ |
||
376 | public function setSource(int $source): self { |
||
381 | |||
382 | /** |
||
383 | * @return int |
||
384 | */ |
||
385 | public function getSource(): int { |
||
388 | |||
389 | |||
390 | /** |
||
391 | * @param ?Member $owner |
||
|
|||
392 | * |
||
393 | * @return self |
||
394 | */ |
||
395 | public function setOwner(?Member $owner): self { |
||
400 | |||
401 | /** |
||
402 | * @return Member |
||
403 | */ |
||
404 | public function getOwner(): Member { |
||
407 | |||
408 | /** |
||
409 | * @return bool |
||
410 | */ |
||
411 | public function hasOwner(): bool { |
||
414 | |||
415 | |||
416 | /** |
||
417 | * @return bool |
||
418 | */ |
||
419 | public function hasMembers(): bool { |
||
422 | |||
423 | /** |
||
424 | * @param array $members |
||
425 | * |
||
426 | * @return self |
||
427 | */ |
||
428 | public function setMembers(array $members): IMemberships { |
||
433 | |||
434 | /** |
||
435 | * @return array |
||
436 | */ |
||
437 | public function getMembers(): array { |
||
444 | |||
445 | |||
446 | /** |
||
447 | * @param array $members |
||
448 | * @param bool $detailed |
||
449 | * |
||
450 | * @return self |
||
451 | */ |
||
452 | public function setInheritedMembers(array $members, bool $detailed): IMemberships { |
||
458 | |||
459 | /** |
||
460 | * @param bool $detailed |
||
461 | * |
||
462 | * @return Member[] |
||
463 | */ |
||
464 | public function getInheritedMembers(bool $detailed = false): array { |
||
472 | |||
473 | |||
474 | /** |
||
475 | * @return bool |
||
476 | */ |
||
477 | public function hasMemberships(): bool { |
||
480 | |||
481 | /** |
||
482 | * @param array $memberships |
||
483 | * |
||
484 | * @return self |
||
485 | */ |
||
486 | public function setMemberships(array $memberships): IMemberships { |
||
491 | |||
492 | /** |
||
493 | * @return Membership[] |
||
494 | */ |
||
495 | public function getMemberships(): array { |
||
502 | |||
503 | |||
504 | /** |
||
505 | * @param Member|null $initiator |
||
506 | * |
||
507 | * @return Circle |
||
508 | */ |
||
509 | public function setInitiator(?Member $initiator): self { |
||
514 | |||
515 | /** |
||
516 | * @return Member |
||
517 | */ |
||
518 | public function getInitiator(): Member { |
||
521 | |||
522 | /** |
||
523 | * @return bool |
||
524 | */ |
||
525 | public function hasInitiator(): bool { |
||
528 | |||
529 | /** |
||
530 | * @param string $instance |
||
531 | * |
||
532 | * @return Circle |
||
533 | */ |
||
534 | public function setInstance(string $instance): self { |
||
541 | |||
542 | /** |
||
543 | * @return string |
||
544 | * @throws OwnerNotFoundException |
||
545 | */ |
||
546 | public function getInstance(): string { |
||
553 | |||
554 | |||
555 | /** |
||
556 | * @param int $population |
||
557 | * |
||
558 | * @return Circle |
||
559 | */ |
||
560 | public function setPopulation(int $population): self { |
||
561 | $this->population = $population; |
||
562 | |||
563 | return $this; |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * @return int |
||
568 | */ |
||
569 | public function getPopulation(): int { |
||
572 | |||
573 | |||
574 | /** |
||
575 | * @param array $settings |
||
576 | * |
||
577 | * @return self |
||
578 | */ |
||
579 | public function setSettings(array $settings): self { |
||
584 | |||
585 | /** |
||
586 | * @return array |
||
587 | */ |
||
588 | public function getSettings(): array { |
||
591 | |||
592 | |||
593 | /** |
||
594 | * @param string $description |
||
595 | * |
||
596 | * @return self |
||
597 | */ |
||
598 | public function setDescription(string $description): self { |
||
603 | |||
604 | /** |
||
605 | * @return string |
||
606 | */ |
||
607 | public function getDescription(): string { |
||
610 | |||
611 | |||
612 | /** |
||
613 | * @return string |
||
614 | */ |
||
615 | public function getUrl(): string { |
||
618 | |||
619 | |||
620 | /** |
||
621 | * @param int $contactAddressBook |
||
622 | * |
||
623 | * @return self |
||
624 | */ |
||
625 | public function setContactAddressBook(int $contactAddressBook): self { |
||
630 | |||
631 | /** |
||
632 | * @return int |
||
633 | */ |
||
634 | public function getContactAddressBook(): int { |
||
637 | |||
638 | |||
639 | /** |
||
640 | * @param string $contactGroupName |
||
641 | * |
||
642 | * @return self |
||
643 | */ |
||
644 | public function setContactGroupName(string $contactGroupName): self { |
||
649 | |||
650 | /** |
||
651 | * @return string |
||
652 | */ |
||
653 | public function getContactGroupName(): string { |
||
656 | |||
657 | |||
658 | /** |
||
659 | * @param int $creation |
||
660 | * |
||
661 | * @return self |
||
662 | */ |
||
663 | public function setCreation(int $creation): self { |
||
668 | |||
669 | /** |
||
670 | * @return int |
||
671 | */ |
||
672 | public function getCreation(): int { |
||
675 | |||
676 | |||
677 | /** |
||
678 | * @param array $data |
||
679 | * |
||
680 | * @return $this |
||
681 | * @throws InvalidItemException |
||
682 | */ |
||
683 | public function import(array $data): IDeserializable { |
||
717 | |||
718 | |||
719 | /** |
||
720 | * @return array |
||
721 | */ |
||
722 | public function jsonSerialize(): array { |
||
756 | |||
757 | |||
758 | /** |
||
759 | * @param array $data |
||
760 | * @param string $prefix |
||
761 | * |
||
762 | * @return INC22QueryRow |
||
763 | * @throws CircleNotFoundException |
||
764 | */ |
||
765 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
790 | |||
791 | |||
792 | /** |
||
793 | * @param Circle $circle |
||
794 | * |
||
795 | * @return bool |
||
796 | * @throws OwnerNotFoundException |
||
797 | */ |
||
798 | public function compareWith(Circle $circle): bool { |
||
819 | |||
820 | |||
821 | /** |
||
822 | * @param Circle $circle |
||
823 | * @param int $display |
||
824 | * |
||
825 | * @return array |
||
826 | */ |
||
827 | public static function getCircleFlags(Circle $circle, int $display = self::FLAGS_LONG): array { |
||
847 | |||
848 | } |
||
849 | |||
850 |
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.