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 |
||
| 32 | class Share implements \OCP\Share\IShare { |
||
| 33 | |||
| 34 | /** @var string */ |
||
| 35 | private $id; |
||
| 36 | /** @var string */ |
||
| 37 | private $providerId; |
||
| 38 | /** @var Node */ |
||
| 39 | private $node; |
||
| 40 | /** @var int */ |
||
| 41 | private $fileId; |
||
| 42 | /** @var string */ |
||
| 43 | private $nodeType; |
||
| 44 | /** @var int */ |
||
| 45 | private $shareType; |
||
| 46 | /** @var string */ |
||
| 47 | private $sharedWith; |
||
| 48 | /** @var string */ |
||
| 49 | private $sharedBy; |
||
| 50 | /** @var string */ |
||
| 51 | private $shareOwner; |
||
| 52 | /** @var int */ |
||
| 53 | private $permissions; |
||
| 54 | /** @var \DateTime */ |
||
| 55 | private $expireDate; |
||
| 56 | /** @var string */ |
||
| 57 | private $password; |
||
| 58 | /** @var string */ |
||
| 59 | private $token; |
||
| 60 | /** @var int */ |
||
| 61 | private $parent; |
||
| 62 | /** @var string */ |
||
| 63 | private $target; |
||
| 64 | /** @var \DateTime */ |
||
| 65 | private $shareTime; |
||
| 66 | /** @var bool */ |
||
| 67 | private $mailSend; |
||
| 68 | /** @var string */ |
||
| 69 | private $name; |
||
| 70 | /** @var int */ |
||
| 71 | private $state; |
||
| 72 | /** @var bool */ |
||
| 73 | private $shouldHashPassword = true; |
||
| 74 | |||
| 75 | /** @var IRootFolder */ |
||
| 76 | private $rootFolder; |
||
| 77 | |||
| 78 | /** @var IUserManager */ |
||
| 79 | private $userManager; |
||
| 80 | |||
| 81 | public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @inheritdoc |
||
| 89 | */ |
||
| 90 | public function setId($id) { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @inheritdoc |
||
| 109 | */ |
||
| 110 | public function getId() { |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @inheritdoc |
||
| 116 | */ |
||
| 117 | public function getFullId() { |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @inheritdoc |
||
| 126 | */ |
||
| 127 | public function setProviderId($id) { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @inheritdoc |
||
| 142 | */ |
||
| 143 | public function setNode(Node $node) { |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @inheritdoc |
||
| 152 | */ |
||
| 153 | public function getNode() { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @inheritdoc |
||
| 180 | */ |
||
| 181 | public function setNodeId($fileId) { |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @inheritdoc |
||
| 189 | */ |
||
| 190 | public function getNodeId() { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @inheritdoc |
||
| 200 | */ |
||
| 201 | public function setNodeType($type) { |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @inheritdoc |
||
| 212 | */ |
||
| 213 | public function getNodeType() { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @inheritdoc |
||
| 224 | */ |
||
| 225 | public function setShareType($shareType) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @inheritdoc |
||
| 232 | */ |
||
| 233 | public function getShareType() { |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @inheritdoc |
||
| 239 | */ |
||
| 240 | public function setSharedWith($sharedWith) { |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @inheritdoc |
||
| 250 | */ |
||
| 251 | public function getSharedWith() { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @inheritdoc |
||
| 257 | */ |
||
| 258 | public function setPermissions($permissions) { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @inheritdoc |
||
| 267 | */ |
||
| 268 | public function getPermissions() { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @inheritdoc |
||
| 274 | */ |
||
| 275 | public function setExpirationDate($expireDate) { |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @inheritdoc |
||
| 284 | */ |
||
| 285 | public function getExpirationDate() { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @inheritdoc |
||
| 291 | */ |
||
| 292 | public function setSharedBy($sharedBy) { |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @inheritdoc |
||
| 304 | */ |
||
| 305 | public function getSharedBy() { |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @inheritdoc |
||
| 312 | */ |
||
| 313 | public function setShareOwner($shareOwner) { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @inheritdoc |
||
| 325 | */ |
||
| 326 | public function getShareOwner() { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @inheritdoc |
||
| 333 | */ |
||
| 334 | public function setPassword($password) { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @inheritdoc |
||
| 341 | */ |
||
| 342 | public function getPassword() { |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @inheritdoc |
||
| 348 | */ |
||
| 349 | public function setToken($token) { |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @inheritdoc |
||
| 356 | */ |
||
| 357 | public function getToken() { |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Set the parent of this share |
||
| 363 | * |
||
| 364 | * @param int parent |
||
| 365 | * @return \OCP\Share\IShare |
||
| 366 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 367 | */ |
||
| 368 | public function setParent($parent) { |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Get the parent of this share. |
||
| 375 | * |
||
| 376 | * @return int |
||
| 377 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
| 378 | */ |
||
| 379 | public function getParent() { |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @inheritdoc |
||
| 385 | */ |
||
| 386 | public function setTarget($target) { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @inheritdoc |
||
| 393 | */ |
||
| 394 | public function getTarget() { |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @inheritdoc |
||
| 400 | */ |
||
| 401 | public function setShareTime(\DateTime $shareTime) { |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @inheritdoc |
||
| 408 | */ |
||
| 409 | public function getShareTime() { |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @inheritdoc |
||
| 415 | */ |
||
| 416 | public function setMailSend($mailSend) { |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @inheritdoc |
||
| 423 | */ |
||
| 424 | public function getMailSend() { |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @inheritdoc |
||
| 430 | */ |
||
| 431 | public function setName($name) { |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @inheritdoc |
||
| 438 | */ |
||
| 439 | public function getName() { |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @inheritdoc |
||
| 445 | */ |
||
| 446 | public function setState($state) { |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @inheritdoc |
||
| 453 | */ |
||
| 454 | public function getState() { |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @inheritdoc |
||
| 460 | */ |
||
| 461 | public function getShouldHashPassword() { |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @inheritdoc |
||
| 467 | */ |
||
| 468 | public function setShouldHashPassword($status) { |
||
| 471 | } |
||
| 472 |