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 | 216 | private function decodeP2PK(array $decoded) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @param ScriptInterface $script |
||
| 44 | * @return bool |
||
| 45 | */ |
||
| 46 | 62 | public function isPayToPublicKey(ScriptInterface $script, &$solution = null) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @param Operation[] $decoded |
||
| 65 | * @return BufferInterface|false |
||
| 66 | */ |
||
| 67 | 180 | private function decodeP2PKH(array $decoded) |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @param ScriptInterface $script |
||
| 99 | * @return bool |
||
| 100 | */ |
||
| 101 | 36 | public function isPayToPublicKeyHash(ScriptInterface $script, &$solution = null) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @param array $decoded |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | 2063 | private function decodeP2SH(array $decoded) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @param ScriptInterface $script |
||
| 148 | * @return bool |
||
| 149 | */ |
||
| 150 | 2003 | public function isPayToScriptHash(ScriptInterface $script, &$solution = null) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @param Operation[] $decoded |
||
| 169 | * @return bool|BufferInterface[] |
||
| 170 | */ |
||
| 171 | 162 | private function decodeMultisig(array $decoded) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * @param ScriptInterface $script |
||
| 206 | * @param mixed $keys |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | 60 | public function isMultisig(ScriptInterface $script, & $keys = []) |
|
| 225 | |||
| 226 | /** |
||
| 227 | * @param ScriptInterface $script |
||
| 228 | * @param Operation[] $decoded |
||
| 229 | * @return false|BufferInterface |
||
| 230 | */ |
||
| 231 | 90 | 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 | 60 | private function decodeWithLimit(ScriptInterface $script, $limit, array $decoded) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * @param ScriptInterface $script |
||
| 275 | * @param Operation[] $decoded |
||
| 276 | * @return BufferInterface|false |
||
| 277 | */ |
||
| 278 | 36 | private function decodeP2WKH(ScriptInterface $script, array $decoded) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * @param ScriptInterface $script |
||
| 285 | * @param Operation[] $decoded |
||
| 286 | * @return BufferInterface|false |
||
| 287 | */ |
||
| 288 | 60 | private function decodeP2WSH(ScriptInterface $script, array $decoded) |
|
| 292 | |||
| 293 | /** |
||
| 294 | * @param ScriptInterface $script |
||
| 295 | * @param null $solution |
||
| 296 | * @return bool |
||
| 297 | */ |
||
| 298 | 30 | public function isWitness(ScriptInterface $script, &$solution = null) |
|
| 314 | |||
| 315 | /** |
||
| 316 | * @param ScriptInterface $script |
||
| 317 | * @param mixed $solution |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | 198 | 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 |