Complex classes like ShareWrapper 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 ShareWrapper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 58 | class ShareWrapper extends ManagedModel implements IDeserializable, INC22QueryRow, JsonSerializable { |
||
| 59 | |||
| 60 | |||
| 61 | use TArrayTools; |
||
| 62 | use TNC22Deserialize; |
||
| 63 | |||
| 64 | |||
| 65 | /** @var string */ |
||
| 66 | private $id = ''; |
||
| 67 | |||
| 68 | /** @var int */ |
||
| 69 | private $permissions = 0; |
||
| 70 | |||
| 71 | /** @var string */ |
||
| 72 | private $itemType = ''; |
||
| 73 | |||
| 74 | /** @var int */ |
||
| 75 | private $itemSource = 0; |
||
| 76 | |||
| 77 | /** @var string */ |
||
| 78 | private $itemTarget = ''; |
||
| 79 | |||
| 80 | /** @var int */ |
||
| 81 | private $fileSource = 0; |
||
| 82 | |||
| 83 | /** @var string */ |
||
| 84 | private $fileTarget = ''; |
||
| 85 | |||
| 86 | /** @var string */ |
||
| 87 | private $token = ''; |
||
| 88 | |||
| 89 | /** @var int */ |
||
| 90 | private $status = 0; |
||
| 91 | |||
| 92 | /** @var string */ |
||
| 93 | private $providerId = ''; |
||
| 94 | |||
| 95 | /** @var DateTime */ |
||
| 96 | private $shareTime = ''; |
||
| 97 | |||
| 98 | /** @var string */ |
||
| 99 | private $sharedWith = ''; |
||
| 100 | |||
| 101 | /** @var string */ |
||
| 102 | private $sharedBy = ''; |
||
| 103 | |||
| 104 | /** @var string */ |
||
| 105 | private $shareOwner = ''; |
||
| 106 | |||
| 107 | /** @var int */ |
||
| 108 | private $shareType = 0; |
||
| 109 | |||
| 110 | /** @var Circle */ |
||
| 111 | private $circle; |
||
| 112 | |||
| 113 | /** @var int */ |
||
| 114 | private $childId = 0; |
||
| 115 | |||
| 116 | /** @var string */ |
||
| 117 | private $childFileTarget = ''; |
||
| 118 | |||
| 119 | /** @var FileCacheWrapper */ |
||
| 120 | private $fileCache; |
||
| 121 | |||
| 122 | /** @var Member */ |
||
| 123 | private $initiator; |
||
| 124 | |||
| 125 | /** @var Member */ |
||
| 126 | private $owner; |
||
| 127 | |||
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $id |
||
| 131 | * |
||
| 132 | * @return ShareWrapper |
||
| 133 | */ |
||
| 134 | public function setId(string $id): self { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getId(): string { |
||
| 146 | |||
| 147 | |||
| 148 | /** |
||
| 149 | * @param int $permissions |
||
| 150 | * |
||
| 151 | * @return ShareWrapper |
||
| 152 | */ |
||
| 153 | public function setPermissions(int $permissions): self { |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return int |
||
| 161 | */ |
||
| 162 | public function getPermissions(): int { |
||
| 165 | |||
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $itemType |
||
| 169 | * |
||
| 170 | * @return ShareWrapper |
||
| 171 | */ |
||
| 172 | public function setItemType(string $itemType): self { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function getItemType(): string { |
||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * @param int $itemSource |
||
| 188 | * |
||
| 189 | * @return ShareWrapper |
||
| 190 | */ |
||
| 191 | public function setItemSource(int $itemSource): self { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return int |
||
| 199 | */ |
||
| 200 | public function getItemSource(): int { |
||
| 203 | |||
| 204 | |||
| 205 | /** |
||
| 206 | * @param string $itemTarget |
||
| 207 | * |
||
| 208 | * @return ShareWrapper |
||
| 209 | */ |
||
| 210 | public function setItemTarget(string $itemTarget): self { |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | public function getItemTarget(): string { |
||
| 222 | |||
| 223 | |||
| 224 | /** |
||
| 225 | * @param int $fileSource |
||
| 226 | * |
||
| 227 | * @return ShareWrapper |
||
| 228 | */ |
||
| 229 | public function setFileSource(int $fileSource): self { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return int |
||
| 237 | */ |
||
| 238 | public function getFileSource(): int { |
||
| 241 | |||
| 242 | |||
| 243 | /** |
||
| 244 | * @param string $fileTarget |
||
| 245 | * |
||
| 246 | * @return ShareWrapper |
||
| 247 | */ |
||
| 248 | public function setFileTarget(string $fileTarget): self { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return string |
||
| 256 | */ |
||
| 257 | public function getFileTarget(): string { |
||
| 260 | |||
| 261 | |||
| 262 | /** |
||
| 263 | * @param string $token |
||
| 264 | * |
||
| 265 | * @return ShareWrapper |
||
| 266 | */ |
||
| 267 | public function setToken(string $token): self { |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @return string |
||
| 275 | */ |
||
| 276 | public function getToken(): string { |
||
| 279 | |||
| 280 | |||
| 281 | /** |
||
| 282 | * @param int $status |
||
| 283 | * |
||
| 284 | * @return ShareWrapper |
||
| 285 | */ |
||
| 286 | public function setStatus(int $status): self { |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return int |
||
| 294 | */ |
||
| 295 | public function getStatus(): int { |
||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $providerId |
||
| 302 | * |
||
| 303 | * @return $this |
||
| 304 | */ |
||
| 305 | public function setProviderId(string $providerId): self { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @return string |
||
| 313 | */ |
||
| 314 | public function getProviderId(): string { |
||
| 317 | |||
| 318 | |||
| 319 | /** |
||
| 320 | * @param DateTime $shareTime |
||
| 321 | * |
||
| 322 | * @return ShareWrapper |
||
| 323 | */ |
||
| 324 | public function setShareTime(DateTime $shareTime): self { |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return DateTime |
||
| 332 | */ |
||
| 333 | public function getShareTime(): DateTime { |
||
| 336 | |||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $sharedWith |
||
| 340 | * |
||
| 341 | * @return ShareWrapper |
||
| 342 | */ |
||
| 343 | public function setSharedWith(string $sharedWith): self { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @return string |
||
| 351 | */ |
||
| 352 | public function getSharedWith(): string { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @param string $sharedBy |
||
| 358 | * |
||
| 359 | * @return ShareWrapper |
||
| 360 | */ |
||
| 361 | public function setSharedBy(string $sharedBy): self { |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function getSharedBy(): string { |
||
| 373 | |||
| 374 | |||
| 375 | /** |
||
| 376 | * @param string $shareOwner |
||
| 377 | * |
||
| 378 | * @return ShareWrapper |
||
| 379 | */ |
||
| 380 | public function setShareOwner(string $shareOwner): self { |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @return string |
||
| 388 | */ |
||
| 389 | public function getShareOwner(): string { |
||
| 392 | |||
| 393 | |||
| 394 | /** |
||
| 395 | * @param int $shareType |
||
| 396 | * |
||
| 397 | * @return ShareWrapper |
||
| 398 | */ |
||
| 399 | public function setShareType(int $shareType): self { |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return int |
||
| 407 | */ |
||
| 408 | public function getShareType(): int { |
||
| 411 | |||
| 412 | |||
| 413 | /** |
||
| 414 | * @param Circle $circle |
||
| 415 | * |
||
| 416 | * @return ShareWrapper |
||
| 417 | */ |
||
| 418 | public function setCircle(Circle $circle): self { |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return Circle |
||
| 426 | */ |
||
| 427 | public function getCircle(): Circle { |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return bool |
||
| 433 | */ |
||
| 434 | public function hasCircle(): bool { |
||
| 437 | |||
| 438 | |||
| 439 | /** |
||
| 440 | * @param int $childId |
||
| 441 | * |
||
| 442 | * @return ShareWrapper |
||
| 443 | */ |
||
| 444 | public function setChildId(int $childId): self { |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return int |
||
| 452 | */ |
||
| 453 | public function getChildId(): int { |
||
| 456 | |||
| 457 | |||
| 458 | /** |
||
| 459 | * @param string $childFileTarget |
||
| 460 | * |
||
| 461 | * @return ShareWrapper |
||
| 462 | */ |
||
| 463 | public function setChildFileTarget(string $childFileTarget): self { |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | public function getChildFileTarget(): string { |
||
| 475 | |||
| 476 | |||
| 477 | /** |
||
| 478 | * @param FileCacheWrapper $fileCache |
||
| 479 | * |
||
| 480 | * @return $this |
||
| 481 | */ |
||
| 482 | public function setFileCache(FileCacheWrapper $fileCache): self { |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @return FileCacheWrapper |
||
| 490 | */ |
||
| 491 | public function getFileCache(): FileCacheWrapper { |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @return bool |
||
| 497 | */ |
||
| 498 | public function hasFileCache(): bool { |
||
| 501 | |||
| 502 | |||
| 503 | /** |
||
| 504 | * @param Member $initiator |
||
| 505 | * |
||
| 506 | * @return ShareWrapper |
||
| 507 | */ |
||
| 508 | public function setInitiator(Member $initiator): self { |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @return Member |
||
| 516 | */ |
||
| 517 | public function getInitiator(): Member { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @return bool |
||
| 523 | */ |
||
| 524 | public function hasViewer(): bool { |
||
| 527 | |||
| 528 | |||
| 529 | /** |
||
| 530 | * @param Member $owner |
||
| 531 | * |
||
| 532 | * @return ShareWrapper |
||
| 533 | */ |
||
| 534 | public function setOwner(Member $owner): self { |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @return Member |
||
| 542 | */ |
||
| 543 | public function getOwner(): Member { |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @return bool |
||
| 549 | */ |
||
| 550 | public function hasOwner(): bool { |
||
| 553 | |||
| 554 | |||
| 555 | /** |
||
| 556 | * @param IRootFolder $rootFolder |
||
| 557 | * @param IUserManager $userManager |
||
| 558 | * @param IURLGenerator $urlGenerator |
||
| 559 | * |
||
| 560 | * @return IShare |
||
| 561 | * @throws IllegalIDChangeException |
||
| 562 | */ |
||
| 563 | public function getShare( |
||
| 600 | |||
| 601 | |||
| 602 | /** |
||
| 603 | * @param IShare $share |
||
| 604 | * @param IURLGenerator $urlGenerator |
||
| 605 | */ |
||
| 606 | private function setShareDisplay(IShare $share, IURLGenerator $urlGenerator) { |
||
| 644 | |||
| 645 | |||
| 646 | public function import(array $data): IDeserializable { |
||
| 695 | |||
| 696 | |||
| 697 | /** |
||
| 698 | * @param array $data |
||
| 699 | * @param string $prefix |
||
| 700 | * |
||
| 701 | * @return INC22QueryRow |
||
| 702 | */ |
||
| 703 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
| 736 | |||
| 737 | |||
| 738 | /** |
||
| 739 | * @return string[] |
||
| 740 | */ |
||
| 741 | public function jsonSerialize(): array { |
||
| 780 | |||
| 781 | } |
||
| 782 | |||
| 783 |