Completed
Push — master ( 410ea8...0c9ae2 )
by thomas
105:23 queued 33:17
created

InputMutator   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 12
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 92
ccs 23
cts 23
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A done() 0 4 1
A replace() 0 10 4
A outpoint() 0 4 1
A null() 0 4 1
A txid() 0 4 1
A vout() 0 4 1
A script() 0 4 1
A sequence() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction\Mutator;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
use BitWasp\Bitcoin\Transaction\OutPoint;
7
use BitWasp\Bitcoin\Transaction\OutPointInterface;
8
use BitWasp\Bitcoin\Transaction\TransactionInput;
9
use BitWasp\Bitcoin\Transaction\TransactionInputInterface;
10
use BitWasp\Buffertools\Buffer;
11
12
class InputMutator
13
{
14
    /**
15
     * @var TransactionInputInterface
16
     */
17
    private $input;
18
19 118
    /**
20
     * @param TransactionInputInterface $input
21 118
     */
22 118
    public function __construct(TransactionInputInterface $input)
23
    {
24
        $this->input = $input;
25
    }
26
27 106
    /**
28
     * @return TransactionInputInterface
29 106
     */
30
    public function done()
31
    {
32
        return $this->input;
33
    }
34
35
    /**
36 112
     * @param array $array
37
     * @return $this
38 112
     */
39 112
    private function replace(array $array = [])
40 112
    {
41 112
        $this->input = new TransactionInput(
42 112
            array_key_exists('outpoint', $array) ? $array['outpoint'] : $this->input->getOutPoint(),
43 112
            array_key_exists('script', $array) ? $array['script'] : $this->input->getScript(),
44
            array_key_exists('nSequence', $array) ? $array['nSequence'] : $this->input->getSequence()
45 112
        );
46
47
        return $this;
48
    }
49
50
    /**
51 6
     * @param OutPointInterface $outPoint
52
     * @return InputMutator
53 6
     */
54
    public function outpoint(OutPointInterface $outPoint)
55
    {
56
        return $this->replace(array('outpoint' => $outPoint));
57
    }
58
59
60 6
    /**
61
     * @return $this
62 6
     */
63
    public function null()
64
    {
65
        return $this->replace(array('outpoint' => new OutPoint(new Buffer(str_pad('', 32, "\x00"), 32), 0xffffffff)));
66
    }
67
68
    /**
69 12
     * @param Buffer $txid
70
     * @return $this
71 12
     */
72
    public function txid(Buffer $txid)
73
    {
74
        return $this->replace(array('txid' => $txid));
75
    }
76
77
    /**
78 106
     * @param int $vout
79
     * @return InputMutator
80 106
     */
81
    public function vout($vout)
82
    {
83
        return $this->replace(array('vout' => $vout));
84
    }
85
86
    /**
87 12
     * @param ScriptInterface $script
88
     * @return $this
89 12
     */
90
    public function script(ScriptInterface $script)
91
    {
92
        return $this->replace(array('script' => $script));
93
    }
94
95
    /**
96
     * @param int $nSequence
97
     * @return $this
98
     */
99
    public function sequence($nSequence)
100
    {
101
        return $this->replace(array('nSequence' => $nSequence));
102
    }
103
}
104