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 $displayName = ''; |
||
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 { |
||
287 | |||
288 | /** |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getName(): string { |
||
294 | |||
295 | |||
296 | /** |
||
297 | * @param string $displayName |
||
298 | * |
||
299 | * @return self |
||
300 | */ |
||
301 | public function setDisplayName(string $displayName): self { |
||
308 | |||
309 | /** |
||
310 | * @return string |
||
311 | */ |
||
312 | public function getDisplayName(): string { |
||
315 | |||
316 | |||
317 | /** |
||
318 | * @param Member $owner |
||
319 | * |
||
320 | * @return self |
||
321 | */ |
||
322 | public function setOwner(Member $owner): self { |
||
327 | |||
328 | /** |
||
329 | * @return Member |
||
330 | */ |
||
331 | public function getOwner(): Member { |
||
334 | |||
335 | /** |
||
336 | * @return bool |
||
337 | */ |
||
338 | public function hasOwner(): bool { |
||
341 | |||
342 | |||
343 | /** |
||
344 | * @param array $members |
||
345 | * |
||
346 | * @return self |
||
347 | */ |
||
348 | public function setMembers(array $members): self { |
||
353 | |||
354 | /** |
||
355 | * @return array |
||
356 | */ |
||
357 | public function getMembers(): array { |
||
364 | |||
365 | |||
366 | /** |
||
367 | * @param Member $initiator |
||
368 | * |
||
369 | * @return Circle |
||
370 | */ |
||
371 | public function setInitiator(Member $initiator): self { |
||
376 | |||
377 | /** |
||
378 | * @return Member |
||
379 | */ |
||
380 | public function getInitiator(): Member { |
||
383 | |||
384 | /** |
||
385 | * @return bool |
||
386 | */ |
||
387 | public function hasInitiator(): bool { |
||
390 | |||
391 | /** |
||
392 | * @param string $instance |
||
393 | * |
||
394 | * @return Circle |
||
395 | */ |
||
396 | public function setInstance(string $instance): self { |
||
403 | |||
404 | /** |
||
405 | * @return string |
||
406 | * @throws OwnerNotFoundException |
||
407 | */ |
||
408 | public function getInstance(): string { |
||
419 | |||
420 | |||
421 | /** |
||
422 | * @param array $settings |
||
423 | * |
||
424 | * @return self |
||
425 | */ |
||
426 | public function setSettings(array $settings): self { |
||
431 | |||
432 | /** |
||
433 | * @return array |
||
434 | */ |
||
435 | public function getSettings(): array { |
||
438 | |||
439 | |||
440 | /** |
||
441 | * @param string $description |
||
442 | * |
||
443 | * @return self |
||
444 | */ |
||
445 | public function setDescription(string $description): self { |
||
450 | |||
451 | /** |
||
452 | * @return string |
||
453 | */ |
||
454 | public function getDescription(): string { |
||
457 | |||
458 | |||
459 | /** |
||
460 | * @param int $contactAddressBook |
||
461 | * |
||
462 | * @return self |
||
463 | */ |
||
464 | public function setContactAddressBook(int $contactAddressBook): self { |
||
469 | |||
470 | /** |
||
471 | * @return int |
||
472 | */ |
||
473 | public function getContactAddressBook(): int { |
||
476 | |||
477 | |||
478 | /** |
||
479 | * @param string $contactGroupName |
||
480 | * |
||
481 | * @return self |
||
482 | */ |
||
483 | public function setContactGroupName(string $contactGroupName): self { |
||
488 | |||
489 | /** |
||
490 | * @return string |
||
491 | */ |
||
492 | public function getContactGroupName(): string { |
||
495 | |||
496 | |||
497 | // /** |
||
498 | // * @param bool $hidden |
||
499 | // * |
||
500 | // * @return Circle |
||
501 | // */ |
||
502 | // public function setHidden(bool $hidden): self { |
||
503 | // $this->hidden = $hidden; |
||
504 | // |
||
505 | // return $this; |
||
506 | // } |
||
507 | // |
||
508 | // /** |
||
509 | // * @return bool |
||
510 | // */ |
||
511 | // public function isHidden(): bool { |
||
512 | // return $this->hidden; |
||
513 | // } |
||
514 | |||
515 | |||
516 | /** |
||
517 | * @param array $memberOf |
||
518 | * |
||
519 | * @return $this |
||
520 | */ |
||
521 | public function setMemberOf(array $memberOf): self { |
||
526 | |||
527 | /** |
||
528 | * @return Circle[] |
||
529 | */ |
||
530 | public function memberOf(): array { |
||
537 | |||
538 | |||
539 | /** |
||
540 | * @param int $creation |
||
541 | * |
||
542 | * @return self |
||
543 | */ |
||
544 | public function setCreation(int $creation): self { |
||
549 | |||
550 | /** |
||
551 | * @return int |
||
552 | */ |
||
553 | public function getCreation(): int { |
||
556 | |||
557 | |||
558 | /** |
||
559 | * @param array $data |
||
560 | * |
||
561 | * @return $this |
||
562 | * @throws InvalidItemException |
||
563 | */ |
||
564 | public function import(array $data): IDeserializable { |
||
596 | |||
597 | |||
598 | /** |
||
599 | * @return array |
||
600 | */ |
||
601 | public function jsonSerialize(): array { |
||
627 | |||
628 | |||
629 | /** |
||
630 | * @param array $data |
||
631 | * @param string $prefix |
||
632 | * |
||
633 | * @return INC21QueryRow |
||
634 | * @throws CircleNotFoundException |
||
635 | */ |
||
636 | public function importFromDatabase(array $data, string $prefix = ''): INC21QueryRow { |
||
659 | |||
660 | |||
661 | /** |
||
662 | * @param Circle $circle |
||
663 | * |
||
664 | * @return bool |
||
665 | * @throws OwnerNotFoundException |
||
666 | */ |
||
667 | public function compareWith(Circle $circle): bool { |
||
688 | |||
689 | |||
690 | /** |
||
691 | * @param Circle $circle |
||
692 | * @param int $display |
||
693 | * |
||
694 | * @return array |
||
695 | */ |
||
696 | public static function getCircleTypes(Circle $circle, int $display = self::TYPES_LONG): array { |
||
716 | |||
717 | } |
||
718 | |||
719 |