Completed
Pull Request — master (#517)
by thomas
68:51 queued 66:33
created

SegwitAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getHRP() 0 5 2
A getAddress() 0 6 2
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
0 ignored issues
show
Bug introduced by
There is one abstract method getScriptPubKey in this class; you could implement it, or declare this class as abstract.
Loading history...
11
{
12
    /**
13
     * @var WitnessProgram
14
     */
15
    protected $witnessProgram;
16
17
    /**
18
     * SegwitAddress constructor.
19
     * @param WitnessProgram $witnessProgram
20
     */
21
    public function __construct(WitnessProgram $witnessProgram)
22
    {
23
        $this->witnessProgram = $witnessProgram;
24
25
        parent::__construct($witnessProgram->getProgram());
26
    }
27
28
    /**
29
     * @param NetworkInterface|null $network
30
     * @return bool
31
     */
32
    public function getHRP(NetworkInterface $network = null)
33
    {
34
        $network = $network ?: Bitcoin::getNetwork();
35
        return $network->getSegwitBech32Prefix();
36
    }
37
38
    /**
39
     * @param NetworkInterface|null $network
40
     * @return string
41
     */
42
    public function getAddress(NetworkInterface $network = null)
43
    {
44
        $network = $network ?: Bitcoin::getNetwork();
0 ignored issues
show
Unused Code introduced by
$network is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
46
        return SegwitBech32::encode($this->witnessProgram);
47
    }
48
}
49