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 UNKNOWN = 'unknown'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param Operation[] $decoded |
||
| 23 | * @return false|BufferInterface |
||
| 24 | */ |
||
| 25 | private function decodeP2PK(array $decoded) |
||
| 41 | 6 | ||
| 42 | 9 | /** |
|
| 43 | * @param ScriptInterface $script |
||
| 44 | * @return bool |
||
| 45 | */ |
||
| 46 | 18 | public function isPayToPublicKey(ScriptInterface $script, &$solution = null) |
|
| 62 | 96 | ||
| 63 | 96 | /** |
|
| 64 | 96 | * @param Operation[] $decoded |
|
| 65 | 96 | * @return BufferInterface|false |
|
| 66 | 96 | */ |
|
| 67 | private function decodeP2PKH(array $decoded) |
||
| 96 | |||
| 97 | /** |
||
| 98 | 2599 | * @param ScriptInterface $script |
|
| 99 | 2599 | * @return bool |
|
| 100 | 2153 | */ |
|
| 101 | public function isPayToPublicKeyHash(ScriptInterface $script, &$solution = null) |
||
| 117 | |||
| 118 | 3 | /** |
|
| 119 | * @param array $decoded |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | 6 | private function decodeP2SH(array $decoded) |
|
| 145 | |||
| 146 | /** |
||
| 147 | 72 | * @param ScriptInterface $script |
|
| 148 | 72 | * @return bool |
|
| 149 | 72 | */ |
|
| 150 | 72 | public function isPayToScriptHash(ScriptInterface $script, &$solution = null) |
|
| 166 | 6 | ||
| 167 | /** |
||
| 168 | * @param Operation[] $decoded |
||
| 169 | * @return bool|BufferInterface[] |
||
| 170 | */ |
||
| 171 | private function decodeMultisig(array $decoded) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param ScriptInterface $script |
||
| 206 | * @param mixed $keys |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | 198 | public function isMultisig(ScriptInterface $script, & $keys = []) |
|
| 225 | 30 | ||
| 226 | 159 | /** |
|
| 227 | * @param ScriptInterface $script |
||
| 228 | 78 | * @param Operation[] $decoded |
|
| 229 | 105 | * @return false|BufferInterface |
|
| 230 | */ |
||
| 231 | 48 | private function decodeWitnessNoLimit(ScriptInterface $script, array $decoded) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * @param ScriptInterface $script |
||
| 256 | * @param int $limit |
||
| 257 | * @param array $decoded |
||
| 258 | * @return BufferInterface|false |
||
| 259 | */ |
||
| 260 | private function decodeWithLimit(ScriptInterface $script, $limit, array $decoded) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param ScriptInterface $script |
||
| 275 | * @param Operation[] $decoded |
||
| 276 | * @return BufferInterface|false |
||
| 277 | */ |
||
| 278 | private function decodeP2WKH(ScriptInterface $script, array $decoded) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @param ScriptInterface $script |
||
| 285 | * @param Operation[] $decoded |
||
| 286 | * @return BufferInterface|false |
||
| 287 | */ |
||
| 288 | private function decodeP2WSH(ScriptInterface $script, array $decoded) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param ScriptInterface $script |
||
| 295 | * @param null $solution |
||
| 296 | * @return bool |
||
| 297 | */ |
||
| 298 | public function isWitness(ScriptInterface $script, &$solution = null) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @param ScriptInterface $script |
||
| 317 | * @param mixed $solution |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | public function classify(ScriptInterface $script, &$solution = null) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param ScriptInterface $script |
||
| 351 | * @return OutputData |
||
| 352 | */ |
||
| 353 | public function decode(ScriptInterface $script) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param ScriptInterface $script |
||
| 362 | * @param mixed $solution |
||
| 363 | * @return string |
||
| 364 | */ |
||
| 365 | public function classifyold(ScriptInterface $script, &$solution = null) |
||
| 392 | } |
||
| 393 |