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

TransactionOutput::getBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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