Complex classes like FilesystemEntity 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 FilesystemEntity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class FilesystemEntity implements EntityInterface |
||
| 23 | { |
||
| 24 | public const TYPE_DOCUMENT = 'document'; |
||
| 25 | public const TYPE_BINARY = 'binary'; |
||
| 26 | public const TYPE_DIRECTORY = 'directory'; |
||
| 27 | public const TYPE_SYMLINK = 'symlink'; |
||
| 28 | |||
| 29 | /** @var int */ |
||
| 30 | private $filesystemId; |
||
| 31 | /** @var int */ |
||
| 32 | private $applicationId; |
||
| 33 | /** @var int */ |
||
| 34 | private $categoryId; |
||
| 35 | /** @var int */ |
||
| 36 | private $parentId; |
||
| 37 | /** @var int */ |
||
| 38 | private $documentId; |
||
| 39 | /** @var int */ |
||
| 40 | private $fileId; |
||
| 41 | /** @var int */ |
||
| 42 | private $directoryId; |
||
| 43 | /** @var int */ |
||
| 44 | private $linkId; |
||
| 45 | /** @var string */ |
||
| 46 | private $path; |
||
| 47 | /** @var string */ |
||
| 48 | private $baseName; |
||
| 49 | /** @var string */ |
||
| 50 | private $title; |
||
| 51 | /** @var string */ |
||
| 52 | private $description; |
||
| 53 | /** @var bool */ |
||
| 54 | private $isHidden; |
||
| 55 | /** @var bool */ |
||
| 56 | private $isReadOnly; |
||
| 57 | /** @var bool */ |
||
| 58 | private $isDeleted; |
||
| 59 | /** @var DateTime */ |
||
| 60 | private $dateCreated; |
||
| 61 | /** @var DateTime */ |
||
| 62 | private $datePublished; |
||
| 63 | /** @var DateTime */ |
||
| 64 | private $dateModified; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Sets the value of the entity identifier. |
||
| 68 | * |
||
| 69 | * @param int $entityId |
||
| 70 | * @return FilesystemEntity |
||
| 71 | */ |
||
| 72 | public function setKeyData(int $entityId) : FilesystemEntity |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Gets the value of the entity identifier. |
||
| 81 | * |
||
| 82 | * @return null|int |
||
| 83 | */ |
||
| 84 | public function getKeyData() : ? int |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param int $filesystemId |
||
| 91 | * @return FilesystemEntity |
||
| 92 | */ |
||
| 93 | public function setFilesystemId(int $filesystemId) : FilesystemEntity |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return null|int |
||
| 102 | */ |
||
| 103 | public function getFilesystemId() : ? int |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param int $applicationId |
||
| 110 | * @return FilesystemEntity |
||
| 111 | */ |
||
| 112 | public function setApplicationId(int $applicationId) : FilesystemEntity |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return null|int |
||
| 121 | */ |
||
| 122 | public function getApplicationId() : ? int |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param null|int $categoryId |
||
| 129 | * @return FilesystemEntity |
||
| 130 | */ |
||
| 131 | public function setCategoryId(? int $categoryId) : FilesystemEntity |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return null|int |
||
| 140 | */ |
||
| 141 | public function getCategoryId() : ? int |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param int|null $parentId |
||
| 148 | * @return FilesystemEntity |
||
| 149 | */ |
||
| 150 | public function setParentId(? int $parentId) : FilesystemEntity |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return null|int |
||
| 159 | */ |
||
| 160 | public function getParentId() : ? int |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return FilesystemEntity |
||
| 167 | */ |
||
| 168 | private function resetType() : FilesystemEntity |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return null|string |
||
| 177 | */ |
||
| 178 | public function getType() : ? string |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param int|null $documentId |
||
| 197 | * @return FilesystemEntity |
||
| 198 | */ |
||
| 199 | public function setDocumentId(? int $documentId) : FilesystemEntity |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return int|null |
||
| 212 | */ |
||
| 213 | public function getDocumentId() : ? int |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param int|null $fileId |
||
| 220 | * @return FilesystemEntity |
||
| 221 | */ |
||
| 222 | public function setFileId(? int $fileId) : FilesystemEntity |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return int|null |
||
| 235 | */ |
||
| 236 | public function getFileId() : ? int |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param int|null $directoryId |
||
| 243 | * @return FilesystemEntity |
||
| 244 | */ |
||
| 245 | public function setDirectoryId(? int $directoryId) : FilesystemEntity |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @return int|null |
||
| 258 | */ |
||
| 259 | public function getDirectoryId() : ? int |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param int|null $linkId |
||
| 266 | * @return FilesystemEntity |
||
| 267 | */ |
||
| 268 | public function setLinkId(? int $linkId) : FilesystemEntity |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @return int|null |
||
| 281 | */ |
||
| 282 | public function getLinkId() : ? int |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param string $path |
||
| 289 | * @return FilesystemEntity |
||
| 290 | */ |
||
| 291 | public function setPath(string $path) : FilesystemEntity |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return string |
||
| 300 | */ |
||
| 301 | public function getPath() : string |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @param string $baseName |
||
| 308 | * @return FilesystemEntity |
||
| 309 | */ |
||
| 310 | public function setBaseName(string $baseName) : FilesystemEntity |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @return null|string |
||
| 319 | */ |
||
| 320 | public function getBaseName() : ? string |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param string $title |
||
| 327 | * @return FilesystemEntity |
||
| 328 | */ |
||
| 329 | public function setTitle(string $title) : FilesystemEntity |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return null|string |
||
| 338 | */ |
||
| 339 | public function getTitle() : ? string |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @param string $description |
||
| 346 | * @return FilesystemEntity |
||
| 347 | */ |
||
| 348 | public function setDescription(string $description) : FilesystemEntity |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return null|string |
||
| 357 | */ |
||
| 358 | public function getDescription() : ? string |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param bool $state |
||
| 365 | * @return FilesystemEntity |
||
| 366 | */ |
||
| 367 | public function setHidden(bool $state) : FilesystemEntity |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return bool |
||
| 376 | */ |
||
| 377 | public function getHidden() : bool |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param bool $state |
||
| 384 | * @return FilesystemEntity |
||
| 385 | */ |
||
| 386 | public function setReadOnly(bool $state) : FilesystemEntity |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @return bool |
||
| 395 | */ |
||
| 396 | public function getReadOnly() : bool |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param bool $state |
||
| 403 | * @return FilesystemEntity |
||
| 404 | */ |
||
| 405 | public function setDeleted(bool $state) : FilesystemEntity |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @return bool |
||
| 414 | */ |
||
| 415 | public function getDeleted() : bool |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @param DateTime $dateCreated |
||
| 422 | * @return FilesystemEntity |
||
| 423 | */ |
||
| 424 | public function setDateCreated(DateTime $dateCreated) : FilesystemEntity |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return null|DateTime |
||
| 433 | */ |
||
| 434 | public function getDateCreated() : ? DateTime |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @param DateTime $dateModified |
||
| 441 | * @return FilesystemEntity |
||
| 442 | */ |
||
| 443 | public function setDateModified(? DateTime $dateModified) : FilesystemEntity |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return null|DateTime |
||
| 452 | */ |
||
| 453 | public function getDateModified() : ? DateTime |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @param DateTime $datePublished |
||
| 460 | * @return FilesystemEntity |
||
| 461 | */ |
||
| 462 | public function setDatePublished(? DateTime $datePublished) : FilesystemEntity |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @return null|DateTime |
||
| 471 | */ |
||
| 472 | public function getDatePublished() : ? DateTime |
||
| 476 | } |
||
| 477 |