Completed
Pull Request — master (#403)
by thomas
73:13 queued 70:38
created

SignData   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
dl 0
loc 107
ccs 27
cts 27
cp 1
rs 10
c 3
b 0
f 1
wmc 12
lcom 3
cbo 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A p2sh() 0 5 1
A hasRedeemScript() 0 4 1
A getRedeemScript() 0 8 2
A p2wsh() 0 5 1
A hasWitnessScript() 0 4 1
A getWitnessScript() 0 8 2
A signaturePolicy() 0 5 1
A hasSignaturePolicy() 0 4 1
A getSignaturePolicy() 0 7 2
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
     * @param ScriptInterface $redeemScript
28
     * @return $this
29
     */
30 30
    public function p2sh(ScriptInterface $redeemScript)
31
    {
32 30
        $this->redeemScript = $redeemScript;
33 30
        return $this;
34
    }
35
36
    /**
37
     * @return bool
38
     */
39 12
    public function hasRedeemScript()
40
    {
41 12
        return $this->redeemScript instanceof ScriptInterface;
42
    }
43
44
    /**
45
     * @return ScriptInterface
46
     */
47 108
    public function getRedeemScript()
48
    {
49 108
        if (null === $this->redeemScript) {
50 6
            throw new \RuntimeException('Redeem script requested but not set');
51
        }
52
53 102
        return $this->redeemScript;
54
    }
55
    /**
56
     * @param ScriptInterface $witnessScript
57
     * @return $this
58
     */
59 24
    public function p2wsh(ScriptInterface $witnessScript)
60
    {
61 24
        $this->witnessScript = $witnessScript;
62 24
        return $this;
63
    }
64
65
    /**
66
     * @return bool
67
     */
68 12
    public function hasWitnessScript()
69
    {
70 12
        return $this->witnessScript instanceof ScriptInterface;
71
    }
72
73
    /**
74
     * @return ScriptInterface
75
     */
76 90
    public function getWitnessScript()
77
    {
78 90
        if (null === $this->witnessScript) {
79 6
            throw new \RuntimeException('Witness script requested but not set');
80
        }
81
82 84
        return $this->witnessScript;
83
    }
84
    
85
    /**
86
     * @param int $flags
87
     * @return $this
88
     */
89 6
    public function signaturePolicy($flags)
90
    {
91 6
        $this->signaturePolicy = $flags;
92 6
        return $this;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98 246
    public function hasSignaturePolicy()
99
    {
100 246
        return $this->signaturePolicy !== null;
101
    }
102
103
    /**
104
     * @return int
105
     */
106 96
    public function getSignaturePolicy()
107
    {
108 96
        if (null === $this->signaturePolicy) {
109 6
            throw new \RuntimeException('Signature policy requested but not set');
110
        }
111 90
        return $this->signaturePolicy;
112
    }
113
}
114