Conditions | 9 |
Paths | 96 |
Total Lines | 60 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
56 | public function sign($nInput, $amount, PrivateKeyInterface $privateKey, ScriptInterface $scriptPubKey, ScriptInterface $redeemScript = null, $sigHashType = SigHash::ALL) |
||
57 | { |
||
58 | |||
59 | if (!isset($this->signatureCreator[$nInput])) { |
||
60 | $this->signatureCreator[$nInput] = new TxSigCreator($this->ecAdapter, $this->tx, $nInput, $amount); |
||
61 | } |
||
62 | |||
63 | /** @var TxSigCreator $sigCreator */ |
||
64 | $sigCreator = $this->signatureCreator[$nInput]; |
||
65 | $sigData = $this->signatures[$nInput]; |
||
66 | $sigVersion = 0; |
||
67 | $scriptSig = $this->tx->getInput($nInput)->getScript(); |
||
68 | $witness = null; |
||
69 | |||
70 | if ($sigData->scriptType === null) { |
||
71 | $classifier = new OutputClassifier($scriptPubKey); |
||
72 | $sigData->innerScriptType = $sigData->scriptType = $classifier->classify($sigData->solution); |
||
73 | } |
||
74 | |||
75 | if ($sigData->scriptType === OutputClassifier::PAYTOSCRIPTHASH) { |
||
76 | $classifier = new OutputClassifier($redeemScript); |
||
|
|||
77 | $sigData->innerScriptType = $classifier->classify(); |
||
78 | } |
||
79 | |||
80 | if ($sigData->scriptType === OutputClassifier::WITNESS_V0_KEYHASH) { |
||
81 | $sigVersion = 1; |
||
82 | $scriptPubKey->isWitness($witness); |
||
83 | $witnessScript = ScriptFactory::sequence([Opcodes::OP_DUP, Opcodes::OP_HASH160, $witness->getProgram(), Opcodes::OP_EQUALVERIFY, Opcodes::OP_CHECKSIG]); |
||
84 | $classifier = new OutputClassifier($witnessScript); |
||
85 | $classifier->classify($sigData->solution); |
||
86 | |||
87 | $sigData->witnessScript = $witnessScript; |
||
88 | $scriptSig = new Script(); |
||
89 | } |
||
90 | |||
91 | if ($sigData->scriptType === OutputClassifier::WITNESS_V0_SCRIPTHASH) { |
||
92 | $sigVersion = 1; |
||
93 | $scriptPubKey->isWitness($witness); |
||
94 | |||
95 | $witnessScript = new Script(end($sigData->witnesses)); |
||
96 | $sigData->witnesses = $sigData->solution; |
||
97 | |||
98 | $classifier = new OutputClassifier($witnessScript); |
||
99 | $sigData->scriptType = $classifier->classify(); |
||
100 | $scriptSig = ScriptFactory::sequence($this->tx->getWitness($nInput)->all()); |
||
101 | } |
||
102 | |||
103 | if ($sigData->scriptType === OutputClassifier::UNKNOWN) { |
||
104 | throw new \RuntimeException('Unsupported scriptPubKey'); |
||
105 | } |
||
106 | |||
107 | if ($sigData->signatures === null) { |
||
108 | $sigCreator->extractSignatures($sigData, $scriptSig, $redeemScript); |
||
109 | |||
110 | } |
||
111 | |||
112 | $sigCreator->signInput($sigData, $privateKey, $redeemScript ?: $scriptPubKey, $sigHashType, $sigVersion); |
||
113 | //print_r($sigData); |
||
114 | return $this; |
||
115 | } |
||
116 | |||
139 |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):