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 |
||
12 | class OutputClassifier |
||
13 | { |
||
14 | const PAYTOPUBKEY = 'pubkey'; |
||
15 | const PAYTOPUBKEYHASH = 'pubkeyhash'; |
||
16 | const PAYTOSCRIPTHASH = 'scripthash'; |
||
17 | const WITNESS_V0_KEYHASH = 'witness_v0_keyhash'; |
||
18 | const WITNESS_V0_SCRIPTHASH = 'witness_v0_scripthash'; |
||
19 | const MULTISIG = 'multisig'; |
||
20 | const NULLDATA = 'nulldata'; |
||
21 | const UNKNOWN = 'nonstandard'; |
||
22 | const NONSTANDARD = 'nonstandard'; |
||
23 | |||
24 | const P2PK = 'pubkey'; |
||
25 | const P2PKH = 'pubkeyhash'; |
||
26 | 372 | const P2SH = 'scripthash'; |
|
27 | const P2WSH = 'witness_v0_scripthash'; |
||
28 | 372 | const P2WKH = 'witness_v0_keyhash'; |
|
29 | 306 | ||
30 | const WITNESS_COINBASE_COMMITMENT = 'witness_coinbase_commitment'; |
||
31 | |||
32 | 174 | /** |
|
33 | 174 | * @param Operation[] $decoded |
|
34 | 84 | * @return false|BufferInterface |
|
35 | 84 | */ |
|
36 | 78 | private function decodeP2PK(array $decoded) |
|
52 | |||
53 | /** |
||
54 | * @param ScriptInterface $script |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function isPayToPublicKey(ScriptInterface $script) |
||
67 | |||
68 | 180 | /** |
|
69 | 180 | * @param Operation[] $decoded |
|
70 | 180 | * @return BufferInterface|false |
|
71 | 180 | */ |
|
72 | 180 | private function decodeP2PKH(array $decoded) |
|
101 | |||
102 | /** |
||
103 | * @param ScriptInterface $script |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function isPayToPublicKeyHash(ScriptInterface $script) |
||
116 | |||
117 | 314 | /** |
|
118 | 314 | * @param array $decoded |
|
119 | 118 | * @return bool |
|
120 | */ |
||
121 | private function decodeP2SH(array $decoded) |
||
144 | |||
145 | /** |
||
146 | * @param ScriptInterface $script |
||
147 | * @return bool |
||
148 | */ |
||
149 | public function isPayToScriptHash(ScriptInterface $script) |
||
159 | |||
160 | /** |
||
161 | 78 | * @param Operation[] $decoded |
|
162 | 78 | * @return bool|BufferInterface[] |
|
163 | 78 | */ |
|
164 | 78 | private function decodeMultisig(array $decoded) |
|
196 | |||
197 | /** |
||
198 | * @param ScriptInterface $script |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function isMultisig(ScriptInterface $script) |
||
211 | 60 | ||
212 | /** |
||
213 | 120 | * @param ScriptInterface $script |
|
214 | 18 | * @param Operation[] $decoded |
|
215 | * @return false|BufferInterface |
||
216 | */ |
||
217 | 108 | private function decodeWitnessNoLimit(ScriptInterface $script, array $decoded) |
|
239 | 102 | ||
240 | 30 | /** |
|
241 | * @param ScriptInterface $script |
||
242 | * @param int $limit |
||
243 | 102 | * @param array $decoded |
|
244 | * @return BufferInterface|false |
||
245 | */ |
||
246 | 42 | private function decodeWithLimit(ScriptInterface $script, $limit, array $decoded) |
|
258 | |||
259 | /** |
||
260 | * @param ScriptInterface $script |
||
261 | * @param Operation[] $decoded |
||
262 | * @return BufferInterface|false |
||
263 | */ |
||
264 | 138 | private function decodeP2WKH(ScriptInterface $script, array $decoded) |
|
268 | |||
269 | /** |
||
270 | * @param ScriptInterface $script |
||
271 | * @param Operation[] $decoded |
||
272 | * @return BufferInterface|false |
||
273 | 30 | */ |
|
274 | private function decodeP2WSH(ScriptInterface $script, array $decoded) |
||
278 | |||
279 | /** |
||
280 | * @param ScriptInterface $script |
||
281 | 6 | * @return bool |
|
282 | */ |
||
283 | public function isWitness(ScriptInterface $script) |
||
293 | |||
294 | 12 | /** |
|
295 | 6 | * @param Operation[] $decoded |
|
296 | * @return false|BufferInterface |
||
297 | */ |
||
298 | 6 | private function decodeNullData(array $decoded) |
|
310 | |||
311 | /** |
||
312 | * @param ScriptInterface $script |
||
313 | * @return bool |
||
314 | */ |
||
315 | public function isNullData(ScriptInterface $script) |
||
324 | 354 | ||
325 | /** |
||
326 | 354 | * @param array $decoded |
|
327 | 66 | * @return bool|BufferInterface |
|
328 | 66 | */ |
|
329 | 336 | private function decodeWitnessCoinbaseCommitment(array $decoded) |
|
348 | |||
349 | 354 | /** |
|
350 | * @param ScriptInterface $script |
||
351 | * @return bool |
||
352 | */ |
||
353 | public function isWitnessCoinbaseCommitment(ScriptInterface $script) |
||
362 | |||
363 | /** |
||
364 | * @param ScriptInterface $script |
||
365 | * @param mixed $solution |
||
366 | * @return string |
||
367 | */ |
||
368 | public function classify(ScriptInterface $script, &$solution = null) |
||
402 | |||
403 | /** |
||
404 | * @param ScriptInterface $script |
||
405 | * @return OutputData |
||
406 | */ |
||
407 | public function decode(ScriptInterface $script) |
||
413 | } |
||
414 |