Complex classes like OutputClassifier 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 OutputClassifier, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class OutputClassifier |
||
| 12 | { |
||
| 13 | const PAYTOPUBKEY = 'pubkey'; |
||
| 14 | const PAYTOPUBKEYHASH = 'pubkeyhash'; |
||
| 15 | const PAYTOSCRIPTHASH = 'scripthash'; |
||
| 16 | const WITNESS_V0_KEYHASH = 'witness_v0_keyhash'; |
||
| 17 | const WITNESS_V0_SCRIPTHASH = 'witness_v0_scripthash'; |
||
| 18 | const MULTISIG = 'multisig'; |
||
| 19 | const NULLDATA = 'nulldata'; |
||
| 20 | const UNKNOWN = 'unknown'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param Operation[] $decoded |
||
| 24 | * @return false|BufferInterface |
||
| 25 | 216 | */ |
|
| 26 | private function decodeP2PK(array $decoded) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param ScriptInterface $script |
||
| 45 | * @return bool |
||
| 46 | 48 | */ |
|
| 47 | public function isPayToPublicKey(ScriptInterface $script) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param Operation[] $decoded |
||
| 60 | * @return BufferInterface|false |
||
| 61 | 180 | */ |
|
| 62 | private function decodeP2PKH(array $decoded) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param ScriptInterface $script |
||
| 94 | * @return bool |
||
| 95 | 36 | */ |
|
| 96 | public function isPayToPublicKeyHash(ScriptInterface $script) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param array $decoded |
||
| 109 | * @return bool |
||
| 110 | 2063 | */ |
|
| 111 | private function decodeP2SH(array $decoded) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param ScriptInterface $script |
||
| 137 | * @return bool |
||
| 138 | 2003 | */ |
|
| 139 | public function isPayToScriptHash(ScriptInterface $script) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param Operation[] $decoded |
||
| 152 | * @return bool|BufferInterface[] |
||
| 153 | 156 | */ |
|
| 154 | private function decodeMultisig(array $decoded) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param ScriptInterface $script |
||
| 189 | * @return bool |
||
| 190 | 1076 | */ |
|
| 191 | public function isMultisig(ScriptInterface $script) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param ScriptInterface $script |
||
| 204 | * @param Operation[] $decoded |
||
| 205 | * @return false|BufferInterface |
||
| 206 | 90 | */ |
|
| 207 | private function decodeWitnessNoLimit(ScriptInterface $script, array $decoded) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param ScriptInterface $script |
||
| 232 | * @param int $limit |
||
| 233 | * @param array $decoded |
||
| 234 | * @return BufferInterface|false |
||
| 235 | 60 | */ |
|
| 236 | private function decodeWithLimit(ScriptInterface $script, $limit, array $decoded) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param ScriptInterface $script |
||
| 251 | * @param Operation[] $decoded |
||
| 252 | * @return BufferInterface|false |
||
| 253 | 36 | */ |
|
| 254 | private function decodeP2WKH(ScriptInterface $script, array $decoded) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param ScriptInterface $script |
||
| 261 | * @param Operation[] $decoded |
||
| 262 | * @return BufferInterface|false |
||
| 263 | 60 | */ |
|
| 264 | private function decodeP2WSH(ScriptInterface $script, array $decoded) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param ScriptInterface $script |
||
| 271 | * @return bool |
||
| 272 | 30 | */ |
|
| 273 | public function isWitness(ScriptInterface $script) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @param Operation[] $decoded |
||
| 286 | * @return false|BufferInterface |
||
| 287 | */ |
||
| 288 | 198 | private function decodeNullData(array $decoded) |
|
| 300 | 136 | ||
| 301 | 48 | /** |
|
| 302 | 48 | * @param ScriptInterface $script |
|
| 303 | 104 | * @return bool |
|
| 304 | 48 | */ |
|
| 305 | 48 | public function isNullData(ScriptInterface $script) |
|
| 314 | 198 | ||
| 315 | /** |
||
| 316 | * @param ScriptInterface $script |
||
| 317 | * @param mixed $solution |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | public function classify(ScriptInterface $script, &$solution = null) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @param ScriptInterface $script |
||
| 354 | * @return OutputData |
||
| 355 | */ |
||
| 356 | public function decode(ScriptInterface $script) |
||
| 362 | } |
||
| 363 |