Completed
Pull Request — master (#88)
by thomas
05:05
created

UTXO   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
A getSignInfo() 0 3 1
1
<?php
2
3
namespace Blocktrail\SDK;
4
5
use BitWasp\Bitcoin\Address\AddressInterface;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
use BitWasp\Bitcoin\Transaction\TransactionOutput;
8
9
class UTXO {
10
11
    public $hash;
12
    public $index;
13
    public $value;
14
15
    /**
16
     * @var AddressInterface
17
     */
18
    public $address;
19
20
    /**
21
     * @var ScriptInterface
22
     */
23
    public $scriptPubKey;
24
    public $path;
25
26
    /**
27
     * @var ScriptInterface
28
     */
29
    public $redeemScript;
30
31
    /**
32
     * @var ScriptInterface|null
33
     */
34
    public $witnessScript;
35
36
    /**
37
     * @var string
38
     */
39
    public $signMode;
40
41
    /**
42
     * UTXO constructor.
43
     * @param $hash
44
     * @param $index
45
     * @param null $value
46
     * @param AddressInterface|null $address
47
     * @param ScriptInterface|null $scriptPubKey
48
     * @param null $path
49
     * @param ScriptInterface|null $redeemScript
50
     * @param ScriptInterface|null $witnessScript
51
     * @param string $signMode
52
     */
53 1
    public function __construct(
54
        $hash,
55
        $index,
56
        $value = null,
57
        AddressInterface $address = null,
58
        ScriptInterface $scriptPubKey = null,
59
        $path = null,
60
        ScriptInterface $redeemScript = null,
61
        ScriptInterface $witnessScript = null,
62
        $signMode = SignInfo::MODE_SIGN
63
    ) {
64 1
        $this->hash = $hash;
65 1
        $this->index = $index;
66 1
        $this->value = $value;
67 1
        $this->address = $address;
68 1
        $this->scriptPubKey = $scriptPubKey;
69 1
        $this->path = $path;
70 1
        $this->redeemScript = $redeemScript;
71 1
        $this->witnessScript = $witnessScript;
72 1
        $this->signMode = $signMode;
73 1
    }
74
75
    /**
76
     * @return SignInfo
77
     */
78
    public function getSignInfo() {
79
        return new SignInfo(new TransactionOutput($this->value, $this->scriptPubKey), $this->signMode, $this->path, $this->redeemScript, $this->witnessScript);
0 ignored issues
show
Bug introduced by
It seems like $this->path can also be of type array; however, Blocktrail\SDK\SignInfo::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
80
    }
81
}
82