Complex classes like IndexObject 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 IndexObject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class IndexObject |
||
| 11 | { |
||
| 12 | public const TYPE_DIR = 1; |
||
| 13 | public const TYPE_FILE = 2; |
||
| 14 | public const TYPE_LINK = 3; |
||
| 15 | |||
| 16 | public const CMP_IGNORE_BLOBID = 1; |
||
| 17 | public const CMP_IGNORE_INODE = 2; |
||
| 18 | |||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $relativePath; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var int |
||
| 27 | */ |
||
| 28 | protected $type; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | protected $mtime; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var int |
||
| 37 | */ |
||
| 38 | protected $ctime; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * mode & 0777 |
||
| 42 | * |
||
| 43 | * @var int |
||
| 44 | */ |
||
| 45 | protected $permissions; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var int |
||
| 49 | */ |
||
| 50 | protected $size; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var int |
||
| 54 | */ |
||
| 55 | protected $inode; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $linkTarget; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Content hashes for file index objects. |
||
| 64 | * |
||
| 65 | * @var HashContainer |
||
| 66 | */ |
||
| 67 | protected $hashes; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $blobId; |
||
| 73 | |||
| 74 | public function __construct(string $relativePath, int $type, int $mtime, int $ctime, int $permissions, ?int $size, ?int $inode, ?string $linkTarget, ?string $blobId, ?HashContainer $hashContainer) |
||
| 93 | |||
| 94 | public function getRelativePath(): string |
||
| 98 | |||
| 99 | public function getBasename(): string |
||
| 105 | |||
| 106 | public function getType(): int |
||
| 110 | |||
| 111 | public function getTypeName(): string |
||
| 115 | |||
| 116 | public function isDirectory(): bool |
||
| 120 | |||
| 121 | public function isFile(): bool |
||
| 125 | |||
| 126 | public function isLink(): bool |
||
| 130 | |||
| 131 | public function getMtime(): int |
||
| 135 | |||
| 136 | public function getCtime(): int |
||
| 140 | |||
| 141 | public function getPermissions(): int |
||
| 145 | |||
| 146 | public function getPermissionsString(): string |
||
| 150 | |||
| 151 | public function getSize(): ?int |
||
| 155 | |||
| 156 | public function getInode(): ?int |
||
| 160 | |||
| 161 | public function getLinkTarget(): ?string |
||
| 165 | |||
| 166 | public function getHashes(): ?HashContainer |
||
| 170 | |||
| 171 | public function getBlobId(): ?string |
||
| 175 | |||
| 176 | public function setBlobId(string $blobId): IndexObject |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Equality check with all attributes. |
||
| 185 | * |
||
| 186 | * @param IndexObject $other |
||
| 187 | * @param int $options |
||
| 188 | * @return bool |
||
| 189 | */ |
||
| 190 | public function equals(?IndexObject $other, int $options = 0): bool |
||
| 215 | |||
| 216 | public function __toString(): string |
||
| 248 | |||
| 249 | public static function getTypeNameMap(): array |
||
| 257 | } |
||
| 258 |