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 |
||
| 11 | class IndexObject implements \ArrayAccess |
||
| 12 | { |
||
| 13 | public const TYPE_DIR = 1; |
||
| 14 | public const TYPE_FILE = 2; |
||
| 15 | public const TYPE_LINK = 3; |
||
| 16 | |||
| 17 | public const CMP_IGNORE_BLOBID = 1; |
||
| 18 | public const CMP_IGNORE_INODE = 2; |
||
| 19 | public const CMP_IGNORE_CTIME = 4; |
||
| 20 | |||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $relativePath; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $type; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var float |
||
| 34 | */ |
||
| 35 | protected $mtime; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var float |
||
| 39 | */ |
||
| 40 | protected $ctime; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * mode & 0777 |
||
| 44 | * |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | protected $permissions; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | protected $size; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | protected $inode; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $linkTarget; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Content hashes for file index objects. |
||
| 66 | * |
||
| 67 | * @var HashContainer |
||
| 68 | */ |
||
| 69 | protected $hashes; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $blobId; |
||
| 75 | |||
| 76 | public function __construct(string $relativePath, int $type, float $mtime, ?float $ctime, int $permissions, ?int $size, ?int $inode, ?string $linkTarget, ?string $blobId, ?HashContainer $hashContainer) |
||
| 95 | |||
| 96 | public function getRelativePath(): string |
||
| 100 | |||
| 101 | public function getBasename(): string |
||
| 107 | |||
| 108 | public function getType(): int |
||
| 112 | |||
| 113 | public function getTypeName(): string |
||
| 117 | |||
| 118 | public function isDirectory(): bool |
||
| 122 | |||
| 123 | public function isFile(): bool |
||
| 127 | |||
| 128 | public function isLink(): bool |
||
| 132 | |||
| 133 | public function getMtime(): float |
||
| 137 | |||
| 138 | public function getCtime(): ?float |
||
| 142 | |||
| 143 | public function setCtime(float $ctime): IndexObject |
||
| 149 | |||
| 150 | public function getPermissions(): int |
||
| 154 | |||
| 155 | public function getPermissionsString(): string |
||
| 159 | |||
| 160 | public function getSize(): ?int |
||
| 164 | |||
| 165 | public function getInode(): ?int |
||
| 169 | |||
| 170 | public function getLinkTarget(): ?string |
||
| 174 | |||
| 175 | public function getHashes(): ?HashContainer |
||
| 179 | |||
| 180 | public function getBlobId(): ?string |
||
| 184 | |||
| 185 | public function setBlobId(string $blobId): IndexObject |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Equality check with all attributes. |
||
| 196 | * |
||
| 197 | * @param IndexObject $other |
||
| 198 | * @param int $options |
||
| 199 | * @return bool |
||
| 200 | */ |
||
| 201 | public function equals(?IndexObject $other, int $options = 0): bool |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @inheritdoc |
||
| 229 | */ |
||
| 230 | public function offsetExists($offset) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @inheritdoc |
||
| 237 | */ |
||
| 238 | public function offsetGet($offset) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @inheritdoc |
||
| 247 | */ |
||
| 248 | public function offsetSet($offset, $value) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @inheritdoc |
||
| 255 | */ |
||
| 256 | public function offsetUnset($offset) |
||
| 260 | |||
| 261 | public function __clone() |
||
| 268 | |||
| 269 | public function __toString(): string |
||
| 299 | |||
| 300 | public static function getTypeNameMap(): array |
||
| 308 | } |
||
| 309 |