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 \DateTime */ |
||
| 61 | private $expireDate; |
||
| 62 | /** @var string */ |
||
| 63 | private $password; |
||
| 64 | /** @var string */ |
||
| 65 | private $token; |
||
| 66 | /** @var int */ |
||
| 67 | private $parent; |
||
| 68 | /** @var string */ |
||
| 69 | private $target; |
||
| 70 | /** @var \DateTime */ |
||
| 71 | private $shareTime; |
||
| 72 | /** @var bool */ |
||
| 73 | private $mailSend; |
||
| 74 | |||
| 75 | /** @var IRootFolder */ |
||
| 76 | private $rootFolder; |
||
| 77 | |||
| 78 | /** @var IUserManager */ |
||
| 79 | private $userManager; |
||
| 80 | |||
| 81 | /** @var ICacheEntry|null */ |
||
| 82 | private $nodeCacheEntry; |
||
| 83 | |||
| 84 | public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @inheritdoc |
||
| 91 | */ |
||
| 92 | public function setId($id) { |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @inheritdoc |
||
| 111 | */ |
||
| 112 | public function getId() { |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @inheritdoc |
||
| 118 | */ |
||
| 119 | public function getFullId() { |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @inheritdoc |
||
| 128 | */ |
||
| 129 | public function setProviderId($id) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @inheritdoc |
||
| 144 | */ |
||
| 145 | public function setNode(Node $node) { |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @inheritdoc |
||
| 154 | */ |
||
| 155 | public function getNode() { |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @inheritdoc |
||
| 183 | */ |
||
| 184 | public function setNodeId($fileId) { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @inheritdoc |
||
| 192 | */ |
||
| 193 | public function getNodeId() { |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @inheritdoc |
||
| 203 | */ |
||
| 204 | public function setNodeType($type) { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @inheritdoc |
||
| 215 | */ |
||
| 216 | public function getNodeType() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @inheritdoc |
||
| 227 | */ |
||
| 228 | public function setShareType($shareType) { |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @inheritdoc |
||
| 235 | */ |
||
| 236 | public function getShareType() { |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @inheritdoc |
||
| 242 | */ |
||
| 243 | public function setSharedWith($sharedWith) { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @inheritdoc |
||
| 253 | */ |
||
| 254 | public function getSharedWith() { |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @inheritdoc |
||
| 260 | */ |
||
| 261 | public function setSharedWithDisplayName($displayName) { |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @inheritdoc |
||
| 271 | */ |
||
| 272 | public function getSharedWithDisplayName() { |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @inheritdoc |
||
| 278 | */ |
||
| 279 | public function setSharedWithAvatar($src) { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @inheritdoc |
||
| 289 | */ |
||
| 290 | public function getSharedWithAvatar() { |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @inheritdoc |
||
| 296 | */ |
||
| 297 | public function setPermissions($permissions) { |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @inheritdoc |
||
| 306 | */ |
||
| 307 | public function getPermissions() { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @inheritdoc |
||
| 313 | */ |
||
| 314 | public function setExpirationDate($expireDate) { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @inheritdoc |
||
| 323 | */ |
||
| 324 | public function getExpirationDate() { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @inheritdoc |
||
| 330 | */ |
||
| 331 | public function setSharedBy($sharedBy) { |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @inheritdoc |
||
| 343 | */ |
||
| 344 | public function getSharedBy() { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @inheritdoc |
||
| 351 | */ |
||
| 352 | public function setShareOwner($shareOwner) { |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @inheritdoc |
||
| 364 | */ |
||
| 365 | public function getShareOwner() { |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @inheritdoc |
||
| 372 | */ |
||
| 373 | public function setPassword($password) { |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @inheritdoc |
||
| 380 | */ |
||
| 381 | public function getPassword() { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @inheritdoc |
||
| 387 | */ |
||
| 388 | public function setToken($token) { |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @inheritdoc |
||
| 395 | */ |
||
| 396 | public function getToken() { |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Set the parent of this share |
||
| 402 | * |
||
| 403 | * @param int parent |
||
| 404 | * @return \OCP\Share\IShare |
||
| 405 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 406 | */ |
||
| 407 | public function setParent($parent) { |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Get the parent of this share. |
||
| 414 | * |
||
| 415 | * @return int |
||
| 416 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 417 | */ |
||
| 418 | public function getParent() { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @inheritdoc |
||
| 424 | */ |
||
| 425 | public function setTarget($target) { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @inheritdoc |
||
| 432 | */ |
||
| 433 | public function getTarget() { |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @inheritdoc |
||
| 439 | */ |
||
| 440 | public function setShareTime(\DateTime $shareTime) { |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @inheritdoc |
||
| 447 | */ |
||
| 448 | public function getShareTime() { |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @inheritdoc |
||
| 454 | */ |
||
| 455 | public function setMailSend($mailSend) { |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @inheritdoc |
||
| 462 | */ |
||
| 463 | public function getMailSend() { |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @inheritdoc |
||
| 469 | */ |
||
| 470 | public function setNodeCacheEntry(ICacheEntry $entry) { |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @inheritdoc |
||
| 476 | */ |
||
| 477 | public function getNodeCacheEntry() { |
||
| 480 | } |
||
| 481 |