Completed
Pull Request — master (#591)
by thomas
34:55
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 7
     */
21
    public function __construct(TransactionOutputInterface $output)
22 7
    {
23 7
        $this->output = $output;
24
    }
25
26
    /**
27
     * @return TransactionOutputInterface
28 6
     */
29
    public function done(): TransactionOutputInterface
30 6
    {
31
        return $this->output;
32
    }
33
34
    /**
35
     * @param array $array
36
     * @return $this
37 3
     */
38
    private function replace(array $array)
39 3
    {
40 3
        $this->output = new TransactionOutput(
41 3
            array_key_exists('value', $array) ? $array['value'] : $this->output->getValue(),
42
            array_key_exists('script', $array) ? $array['script'] : $this->output->getScript()
43
        );
44 3
45
        return $this;
46
    }
47
48
    /**
49
     * @param int $value
50 1
     * @return $this
51
     */
52 1
    public function value(int $value)
53
    {
54
        return $this->replace(array('value' => $value));
55
    }
56
57
    /**
58
     * @param ScriptInterface $script
59 2
     * @return $this
60
     */
61 2
    public function script(ScriptInterface $script)
62
    {
63
        return $this->replace(array('script' => $script));
64
    }
65
}
66