Completed
Pull Request — master (#744)
by thomas
23:27
created

Slip132   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 111
ccs 16
cts 20
cp 0.8
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 6

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A loadPrefix() 0 5 1
A p2pkh() 0 4 1
A p2shP2wpkh() 0 4 1
A p2shP2wshP2pkh() 0 4 1
A p2shP2wshMultisig() 0 4 1
A p2wpkh() 0 4 1
A p2wshP2pkh() 0 4 1
A p2wshMultisig() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Key\Deterministic\Slip132;
6
7
use BitWasp\Bitcoin\Bitcoin;
8
use BitWasp\Bitcoin\Exceptions\NotImplementedException;
9
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix;
10
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory;
11
use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper;
12
13
class Slip132
14
{
15
    /**
16
     * @var KeyToScriptHelper
17
     */
18
    private $helper;
19
20
    /**
21
     * Slip132PrefixRegistry constructor.
22
23
     * @param KeyToScriptHelper $helper
24
     */
25 20
    public function __construct(KeyToScriptHelper $helper = null)
26
    {
27 20
        $this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter());
28 20
    }
29
30
    /**
31
     * @param PrefixRegistry $registry
32
     * @param ScriptDataFactory $factory
33
     * @return ScriptPrefix
34
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
35
     */
36 16
    private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory): ScriptPrefix
37
    {
38 16
        list ($private, $public) = $registry->getPrefixes($factory->getScriptType());
39 16
        return new ScriptPrefix($factory, $private, $public);
40
    }
41
42
    /**
43
     * xpub on bitcoin
44
     * @param PrefixRegistry $registry
45
     * @return ScriptPrefix
46
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
47
     */
48 6
    public function p2pkh(PrefixRegistry $registry): ScriptPrefix
49
    {
50 6
        return $this->loadPrefix($registry, $this->helper->getP2pkhFactory());
51
    }
52
53
    /**
54
     * ypub on bitcoin
55
     * @param PrefixRegistry $registry
56
     * @return ScriptPrefix
57
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
58
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
59
     */
60 4
    public function p2shP2wpkh(PrefixRegistry $registry): ScriptPrefix
61
    {
62 4
        return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory()));
63
    }
64
65
    /**
66
     * Ypub on bitcoin
67
     * @param PrefixRegistry $registry
68
     * @return ScriptPrefix
69
     * @throws NotImplementedException
70
     */
71 2
    public function p2shP2wshP2pkh(PrefixRegistry $registry): ScriptPrefix
0 ignored issues
show
Unused Code introduced by
The parameter $registry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73 2
        throw new NotImplementedException("Ypub/prv not supported yet");
74
    }
75
76
    /**
77
     * Ypub on bitcoin
78
     * @param int $m
79
     * @param int $n
80
     * @param bool $sortKeys
81
     * @param PrefixRegistry $registry
82
     * @return ScriptPrefix
83
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
84
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
85
     */
86
    public function p2shP2wshMultisig(int $m, int $n, bool $sortKeys, PrefixRegistry $registry): ScriptPrefix
87
    {
88
        return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getMultisigFactory($m, $n, $sortKeys)));
89
    }
90
91
    /**
92
     * zpub on bitcoin
93
     * @param PrefixRegistry $registry
94
     * @return ScriptPrefix
95
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
96
     */
97 6
    public function p2wpkh(PrefixRegistry $registry): ScriptPrefix
98
    {
99 6
        return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory());
100
    }
101
102
    /**
103
     * Zpub on bitcoin
104
     * @param PrefixRegistry $registry
105
     * @return ScriptPrefix
106
     * @throws NotImplementedException
107
     */
108 2
    public function p2wshP2pkh(PrefixRegistry $registry): ScriptPrefix
0 ignored issues
show
Unused Code introduced by
The parameter $registry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
    {
110 2
        throw new NotImplementedException("Zpub/prv not supported yet");
111
    }
112
    /**
113
     * Zpub on bitcoin
114
     * @param PrefixRegistry $registry
115
     * @return ScriptPrefix
116
     * @throws NotImplementedException
117
     */
118
    public function p2wshMultisig(int $m, int $n, bool $sortKeys, PrefixRegistry $registry): ScriptPrefix
119
    {
120
        return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getMultisigFactory($m, $n, $sortKeys)));
121
        throw new NotImplementedException("Zpub/prv not supported yet");
0 ignored issues
show
Unused Code introduced by
throw new \BitWasp\Bitco...rv not supported yet'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
122
    }
123
}
124