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 | 340 | const NONSTANDARD = 'nonstandard'; |
|
| 21 | |||
| 22 | 340 | /** |
|
| 23 | 340 | * @var \BitWasp\Bitcoin\Script\Parser\Operation[] |
|
| 24 | */ |
||
| 25 | private $decoded; |
||
| 26 | |||
| 27 | /** |
||
| 28 | 202 | * @var ScriptInterface |
|
| 29 | */ |
||
| 30 | 202 | private $script; |
|
| 31 | 160 | ||
| 32 | /** |
||
| 33 | * @param ScriptInterface $script |
||
| 34 | 60 | */ |
|
| 35 | 60 | public function __construct(ScriptInterface $script) |
|
| 40 | |||
| 41 | /** |
||
| 42 | 18 | * @param BufferInterface|null $publicKey |
|
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | public function isPayToPublicKey(& $publicKey = null) |
||
| 62 | 112 | ||
| 63 | 24 | /** |
|
| 64 | * @param BufferInterface|null $pubKeyHash |
||
| 65 | 112 | * @return bool |
|
| 66 | */ |
||
| 67 | 88 | public function isPayToPublicKeyHash(& $pubKeyHash = null) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * @param BufferInterface|null $scriptHash |
||
| 100 | 172 | * @return bool |
|
| 101 | */ |
||
| 102 | 172 | public function isPayToScriptHash(& $scriptHash = null) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * @param BufferInterface[] $keys |
||
| 130 | 102 | * @return bool |
|
| 131 | */ |
||
| 132 | 102 | public function isMultisig(& $keys = []) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @param BufferInterface $programHash |
||
| 168 | * @return bool |
||
| 169 | */ |
||
| 170 | public function isWitness(& $programHash = null) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param BufferInterface|BufferInterface[] $solutions |
||
| 201 | * @return string |
||
| 202 | */ |
||
| 203 | public function classify(&$solutions = null) |
||
| 232 | } |
||
| 233 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: