Completed
Pull Request — master (#525)
by thomas
26:53
created

SignData::hasSignaturePolicy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction\Factory;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
7
class SignData
8
{
9
    // Todo: review for useful exception?
10
11
    /**
12
     * @var ScriptInterface
13
     */
14
    protected $redeemScript = null;
15
16
    /**
17
     * @var ScriptInterface
18
     */
19
    protected $witnessScript = null;
20
21
    /**
22
     * @var int
23
     */
24
    protected $signaturePolicy = null;
25
26
    /**
27
     * @var bool[]
28
     */
29
    protected $logicalPath = null;
30
31
    /**
32
     * @param ScriptInterface $redeemScript
33
     * @return $this
34
     */
35 4
    public function p2sh(ScriptInterface $redeemScript)
36
    {
37 4
        $this->redeemScript = $redeemScript;
38 4
        return $this;
39
    }
40
41
    /**
42
     * @return bool
43
     */
44 80
    public function hasRedeemScript()
45
    {
46 80
        return $this->redeemScript instanceof ScriptInterface;
47
    }
48
49
    /**
50
     * @return ScriptInterface
51
     */
52 46
    public function getRedeemScript()
53
    {
54 46
        if (null === $this->redeemScript) {
55 2
            throw new \RuntimeException('Redeem script requested but not set');
56
        }
57
58 44
        return $this->redeemScript;
59
    }
60
61
    /**
62
     * @param ScriptInterface $witnessScript
63
     * @return $this
64
     */
65 4
    public function p2wsh(ScriptInterface $witnessScript)
66
    {
67 4
        $this->witnessScript = $witnessScript;
68 4
        return $this;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74 80
    public function hasWitnessScript()
75
    {
76 80
        return $this->witnessScript instanceof ScriptInterface;
77
    }
78
79
    /**
80
     * @return ScriptInterface
81
     */
82 40
    public function getWitnessScript()
83
    {
84 40
        if (null === $this->witnessScript) {
85 2
            throw new \RuntimeException('Witness script requested but not set');
86
        }
87
88 38
        return $this->witnessScript;
89
    }
90
    
91
    /**
92
     * @param int $flags
93
     * @return $this
94
     */
95 2
    public function signaturePolicy($flags)
96
    {
97 2
        $this->signaturePolicy = $flags;
98 2
        return $this;
99
    }
100
101
    /**
102
     * @return bool
103
     */
104 164
    public function hasSignaturePolicy()
105
    {
106 164
        return $this->signaturePolicy !== null;
107
    }
108
109
    /**
110
     * @return int
111
     */
112 54
    public function getSignaturePolicy()
113
    {
114 54
        if (null === $this->signaturePolicy) {
115 2
            throw new \RuntimeException('Signature policy requested but not set');
116
        }
117 52
        return $this->signaturePolicy;
118
    }
119
120
    /**
121
     * @param bool[] $vfPathTaken
122
     * @return $this
123
     */
124 36
    public function logicalPath(array $vfPathTaken)
125
    {
126 36
        foreach ($vfPathTaken as $value) {
127 22
            if (!is_bool($value)) {
128 22
                throw new \RuntimeException("Invalid values for logical path, must be a boolean array");
129
            }
130
        }
131
132 36
        $this->logicalPath = $vfPathTaken;
133 36
        return $this;
134
    }
135
136
    /**
137
     * @return bool
138
     */
139
    public function hasLogicalPath()
140
    {
141
        return is_array($this->logicalPath);
142
    }
143
144
    /**
145
     * @return bool[]
146
     */
147 22
    public function getLogicalPath()
148
    {
149 22
        if (null === $this->logicalPath) {
150
            throw new \RuntimeException("Logical path requested but not set");
151
        }
152
153 22
        return $this->logicalPath;
154
    }
155
}
156