Completed
Pull Request — master (#591)
by thomas
23:06 queued 05:47
created

OutputMutator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A done() 0 4 1
A replace() 0 9 3
A value() 0 4 1
A script() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Transaction\Mutator;
6
7
use BitWasp\Bitcoin\Script\ScriptInterface;
8
use BitWasp\Bitcoin\Transaction\TransactionOutput;
9
use BitWasp\Bitcoin\Transaction\TransactionOutputInterface;
10
11
class OutputMutator
12
{
13
    /**
14
     * @var TransactionOutputInterface
15
     */
16
    private $output;
17
18
    /**
19
     * @param TransactionOutputInterface $output
20
     */
21 6
    public function __construct(TransactionOutputInterface $output)
22
    {
23 6
        $this->output = $output;
24 6
    }
25
26
    /**
27
     * @return TransactionOutputInterface
28
     */
29 5
    public function done(): TransactionOutputInterface
30
    {
31 5
        return $this->output;
32
    }
33
34
    /**
35
     * @param array $array
36
     * @return $this
37
     */
38 2
    private function replace(array $array)
39
    {
40 2
        $this->output = new TransactionOutput(
41 2
            array_key_exists('value', $array) ? $array['value'] : $this->output->getValue(),
42 2
            array_key_exists('script', $array) ? $array['script'] : $this->output->getScript()
43
        );
44
45 2
        return $this;
46
    }
47
48
    /**
49
     * @param int $value
50
     * @return $this
51
     */
52 2
    public function value(int $value)
53
    {
54 2
        return $this->replace(array('value' => $value));
55
    }
56
57
    /**
58
     * @param ScriptInterface $script
59
     * @return $this
60
     */
61 2
    public function script(ScriptInterface $script)
62
    {
63 2
        return $this->replace(array('script' => $script));
64
    }
65
}
66