Complex classes like Share 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 Share, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Share implements \OCP\Share\IShare { |
||
| 35 | |||
| 36 | /** @var string */ |
||
| 37 | private $id; |
||
| 38 | /** @var string */ |
||
| 39 | private $providerId; |
||
| 40 | /** @var Node */ |
||
| 41 | private $node; |
||
| 42 | /** @var int */ |
||
| 43 | private $fileId; |
||
| 44 | /** @var string */ |
||
| 45 | private $nodeType; |
||
| 46 | /** @var int */ |
||
| 47 | private $shareType; |
||
| 48 | /** @var string */ |
||
| 49 | private $sharedWith; |
||
| 50 | /** @var string */ |
||
| 51 | private $sharedWithDisplayName; |
||
| 52 | /** @var string */ |
||
| 53 | private $sharedWithAvatar; |
||
| 54 | /** @var string */ |
||
| 55 | private $sharedBy; |
||
| 56 | /** @var string */ |
||
| 57 | private $shareOwner; |
||
| 58 | /** @var int */ |
||
| 59 | private $permissions; |
||
| 60 | /** @var string */ |
||
| 61 | private $note = ''; |
||
| 62 | /** @var \DateTime */ |
||
| 63 | private $expireDate; |
||
| 64 | /** @var string */ |
||
| 65 | private $password; |
||
| 66 | /** @var bool */ |
||
| 67 | private $sendPasswordByTalk = false; |
||
| 68 | /** @var string */ |
||
| 69 | private $token; |
||
| 70 | /** @var int */ |
||
| 71 | private $parent; |
||
| 72 | /** @var string */ |
||
| 73 | private $target; |
||
| 74 | /** @var \DateTime */ |
||
| 75 | private $shareTime; |
||
| 76 | /** @var bool */ |
||
| 77 | private $mailSend; |
||
| 78 | |||
| 79 | /** @var IRootFolder */ |
||
| 80 | private $rootFolder; |
||
| 81 | |||
| 82 | /** @var IUserManager */ |
||
| 83 | private $userManager; |
||
| 84 | |||
| 85 | /** @var ICacheEntry|null */ |
||
| 86 | private $nodeCacheEntry; |
||
| 87 | |||
| 88 | public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @inheritdoc |
||
| 95 | */ |
||
| 96 | public function setId($id) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @inheritdoc |
||
| 115 | */ |
||
| 116 | public function getId() { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @inheritdoc |
||
| 122 | */ |
||
| 123 | public function getFullId() { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @inheritdoc |
||
| 132 | */ |
||
| 133 | public function setProviderId($id) { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @inheritdoc |
||
| 148 | */ |
||
| 149 | public function setNode(Node $node) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @inheritdoc |
||
| 158 | */ |
||
| 159 | public function getNode() { |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @inheritdoc |
||
| 187 | */ |
||
| 188 | public function setNodeId($fileId) { |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @inheritdoc |
||
| 196 | */ |
||
| 197 | public function getNodeId() { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @inheritdoc |
||
| 207 | */ |
||
| 208 | public function setNodeType($type) { |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @inheritdoc |
||
| 219 | */ |
||
| 220 | public function getNodeType() { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @inheritdoc |
||
| 231 | */ |
||
| 232 | public function setShareType($shareType) { |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @inheritdoc |
||
| 239 | */ |
||
| 240 | public function getShareType() { |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @inheritdoc |
||
| 246 | */ |
||
| 247 | public function setSharedWith($sharedWith) { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @inheritdoc |
||
| 257 | */ |
||
| 258 | public function getSharedWith() { |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @inheritdoc |
||
| 264 | */ |
||
| 265 | public function setSharedWithDisplayName($displayName) { |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @inheritdoc |
||
| 275 | */ |
||
| 276 | public function getSharedWithDisplayName() { |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @inheritdoc |
||
| 282 | */ |
||
| 283 | public function setSharedWithAvatar($src) { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @inheritdoc |
||
| 293 | */ |
||
| 294 | public function getSharedWithAvatar() { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @inheritdoc |
||
| 300 | */ |
||
| 301 | public function setPermissions($permissions) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @inheritdoc |
||
| 310 | */ |
||
| 311 | public function getPermissions() { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @inheritdoc |
||
| 317 | */ |
||
| 318 | public function setNote($note) { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @inheritdoc |
||
| 325 | */ |
||
| 326 | public function getNote() { |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @inheritdoc |
||
| 335 | */ |
||
| 336 | public function setExpirationDate($expireDate) { |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @inheritdoc |
||
| 345 | */ |
||
| 346 | public function getExpirationDate() { |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @inheritdoc |
||
| 352 | */ |
||
| 353 | public function setSharedBy($sharedBy) { |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @inheritdoc |
||
| 365 | */ |
||
| 366 | public function getSharedBy() { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @inheritdoc |
||
| 373 | */ |
||
| 374 | public function setShareOwner($shareOwner) { |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @inheritdoc |
||
| 386 | */ |
||
| 387 | public function getShareOwner() { |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @inheritdoc |
||
| 394 | */ |
||
| 395 | public function setPassword($password) { |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @inheritdoc |
||
| 402 | */ |
||
| 403 | public function getPassword() { |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @inheritdoc |
||
| 409 | */ |
||
| 410 | public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @inheritdoc |
||
| 417 | */ |
||
| 418 | public function getSendPasswordByTalk(): bool { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @inheritdoc |
||
| 424 | */ |
||
| 425 | public function setToken($token) { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @inheritdoc |
||
| 432 | */ |
||
| 433 | public function getToken() { |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Set the parent of this share |
||
| 439 | * |
||
| 440 | * @param int parent |
||
| 441 | * @return \OCP\Share\IShare |
||
| 442 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 443 | */ |
||
| 444 | public function setParent($parent) { |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Get the parent of this share. |
||
| 451 | * |
||
| 452 | * @return int |
||
| 453 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 454 | */ |
||
| 455 | public function getParent() { |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @inheritdoc |
||
| 461 | */ |
||
| 462 | public function setTarget($target) { |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @inheritdoc |
||
| 469 | */ |
||
| 470 | public function getTarget() { |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @inheritdoc |
||
| 476 | */ |
||
| 477 | public function setShareTime(\DateTime $shareTime) { |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @inheritdoc |
||
| 484 | */ |
||
| 485 | public function getShareTime() { |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @inheritdoc |
||
| 491 | */ |
||
| 492 | public function setMailSend($mailSend) { |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @inheritdoc |
||
| 499 | */ |
||
| 500 | public function getMailSend() { |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @inheritdoc |
||
| 506 | */ |
||
| 507 | public function setNodeCacheEntry(ICacheEntry $entry) { |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @inheritdoc |
||
| 513 | */ |
||
| 514 | public function getNodeCacheEntry() { |
||
| 517 | } |
||
| 518 |