Completed
Push — master ( f68fb5...fceb66 )
by thomas
22:42
created

BitcoinCashChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 9
cts 14
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B getSigHash() 0 26 5
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Interpreter;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer;
7
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher;
8
use BitWasp\Bitcoin\Transaction\SignatureHash\SigHash;
9
use BitWasp\Bitcoin\Transaction\SignatureHash\V1Hasher;
10
use BitWasp\Buffertools\Buffer;
11
use BitWasp\Buffertools\BufferInterface;
12
13
class BitcoinCashChecker extends Checker
14
{
15
    protected $sigHashOptionalBits = SigHash::ANYONECANPAY | SigHash::BITCOINCASH;
16
17
    /**
18
     * @param ScriptInterface $script
19
     * @param int $sigHashType
20
     * @param int $sigVersion
21
     * @return BufferInterface
22
     */
23 2
    public function getSigHash(ScriptInterface $script, $sigHashType, $sigVersion)
24
    {
25 2
        if ($sigVersion !== 0) {
26
            throw new \RuntimeException("SigVersion must be 0");
27
        }
28
29 2
        $cacheCheck = $sigVersion . $sigHashType . $script->getBuffer()->getBinary();
30 2
        if (!isset($this->sigHashCache[$cacheCheck])) {
31 2
            if ($sigHashType & SigHash::BITCOINCASH) {
32 2
                $hasher = new V1Hasher($this->transaction, $this->amount);
33
            } else {
34
                if ($this->hasherV0) {
35
                    $hasher = $this->hasherV0;
36
                } else {
37
                    $hasher = $this->hasherV0 = new Hasher($this->transaction, new TransactionSerializer());
0 ignored issues
show
Unused Code introduced by
The call to Hasher::__construct() has too many arguments starting with new \BitWasp\Bitcoin\Ser...TransactionSerializer().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
                }
39
            }
40
41 2
            $hash = $hasher->calculate($script, $this->nInput, $sigHashType);
42 2
            $this->sigHashCache[$cacheCheck] = $hash->getBinary();
43
        } else {
44
            $hash = new Buffer($this->sigHashCache[$cacheCheck], 32, $this->adapter->getMath());
45
        }
46
47 2
        return $hash;
48
    }
49
}
50