Complex classes like BinaryData 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 BinaryData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class BinaryData { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @var int |
||
| 9 | */ |
||
| 10 | private $type; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var mixed |
||
| 14 | */ |
||
| 15 | private $value; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | private $keyType; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | private $valueType; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param array $dataType |
||
| 29 | * @param mixed $value |
||
| 30 | */ |
||
| 31 | public function __construct(array $dataType, $value) { |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function __toString() { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Return binary uuid |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | private function getUUID() { |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | private function getList() { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | private function getMap() { |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | private function getText() { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | private function getBigInt() { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | private function getVarInt() { |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | private function getTimestamp() { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | private function getBlob() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | private function getBoolean() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return string |
||
| 192 | */ |
||
| 193 | private function getDecimal() { |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @return string |
||
| 208 | */ |
||
| 209 | private function getDouble() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | private function getFloat() { |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | private function getInet() { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | private function getInt() { |
||
| 233 | |||
| 234 | /** |
||
| 235 | * |
||
| 236 | * @param string $dec |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | private function bcdechex($dec) { |
||
| 248 | } |
||
| 249 |