Completed
Push — master ( 1989a1...e79d55 )
by thomas
37:47
created

TransactionOutput   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 71
ccs 15
cts 18
cp 0.8333
rs 10
c 2
b 0
f 1
wmc 7
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __clone() 0 4 1
A getValue() 0 4 1
A getScript() 0 4 1
A equals() 0 9 2
A getBuffer() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
use BitWasp\Bitcoin\Serializable;
7
use BitWasp\Bitcoin\Serializer\Transaction\TransactionOutputSerializer;
8
9
class TransactionOutput extends Serializable implements TransactionOutputInterface
10
{
11
12
    /**
13
     * @var string|int
14
     */
15
    private $value;
16
17
    /**
18
     * @var ScriptInterface
19
     */
20
    private $script;
21
22
    /**
23
     * Initialize class
24
     *
25
     * @param int $value
26
     * @param ScriptInterface $script
27
     */
28 2428
    public function __construct($value, ScriptInterface $script)
29
    {
30 2428
        $this->value = $value;
31 2428
        $this->script = $script;
32 2428
    }
33
34
    /**
35
     * @return void
36
     */
37
    public function __clone()
38
    {
39
        $this->script = clone $this->script;
40
    }
41
42
    /**
43
     * @see TransactionOutputInterface::getValue()
44
     */
45 2377
    public function getValue()
46
    {
47 2377
        return $this->value;
48
    }
49
50
    /**
51
     * @see TransactionOutputInterface::getScript()
52
     */
53 2371
    public function getScript()
54
    {
55 2371
        return $this->script;
56
    }
57
58
    /**
59
     * @param TransactionOutputInterface $output
60
     * @return bool
61
     */
62 6
    public function equals(TransactionOutputInterface $output)
63
    {
64 6
        $script = $this->script->equals($output->getScript());
65 6
        if (!$script) {
66 6
            return false;
67
        }
68
69 6
        return gmp_cmp($this->value, $output->getValue()) === 0;
70
    }
71
72
    /**
73
     * @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
74
     */
75 2317
    public function getBuffer()
76
    {
77 2317
        return (new TransactionOutputSerializer())->serialize($this);
78
    }
79
}
80