Completed
Push — 0.0.35 ( b2fc74...d8d049 )
by thomas
28:12 queued 09:10
created

SegwitAddress   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getHRP() 0 5 2
A getScriptPubKey() 0 4 1
A getAddress() 0 6 2
A getWitnessProgram() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Address;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Network\NetworkInterface;
7
use BitWasp\Bitcoin\Script\WitnessProgram;
8
use BitWasp\Bitcoin\SegwitBech32;
9
10
class SegwitAddress extends Address implements Bech32AddressInterface
11
{
12
    /**
13
     * @var WitnessProgram
14
     */
15
    protected $witnessProgram;
16
17
    /**
18
     * SegwitAddress constructor.
19
     * @param WitnessProgram $witnessProgram
20
     */
21 9
    public function __construct(WitnessProgram $witnessProgram)
22
    {
23 9
        $this->witnessProgram = $witnessProgram;
24
25 9
        parent::__construct($witnessProgram->getProgram());
26 9
    }
27
28
    /**
29
     * @param NetworkInterface|null $network
30
     * @return bool
31
     */
32 6
    public function getHRP(NetworkInterface $network = null)
33
    {
34 6
        $network = $network ?: Bitcoin::getNetwork();
35 6
        return $network->getSegwitBech32Prefix();
36
    }
37
38
    /**
39
     * @return \BitWasp\Bitcoin\Script\ScriptInterface
40
     */
41 6
    public function getScriptPubKey()
42
    {
43 6
        return $this->witnessProgram->getScript();
44
    }
45
46
    /**
47
     * @return WitnessProgram
48
     */
49
    public function getWitnessProgram()
50
    {
51
        return $this->witnessProgram;
52
    }
53
54
    /**
55
     * @param NetworkInterface|null $network
56
     * @return string
57
     */
58 7
    public function getAddress(NetworkInterface $network = null)
59
    {
60 7
        $network = $network ?: Bitcoin::getNetwork();
61
62 7
        return SegwitBech32::encode($this->witnessProgram, $network);
63
    }
64
}
65