Completed
Push — master ( 883b2a...6b2c83 )
by thomas
44:21 queued 41:03
created

TransactionOutput::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
crap 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
use BitWasp\CommonTrait\FunctionAliasArrayAccess;
9
10
class TransactionOutput extends Serializable implements TransactionOutputInterface
11
{
12
    use FunctionAliasArrayAccess;
13
14
    /**
15
     * @var string|int
16
     */
17
    private $value;
18
19
    /**
20
     * @var ScriptInterface
21
     */
22
    private $script;
23
24
    /**
25
     * Initialize class
26
     *
27
     * @param int $value
28
     * @param ScriptInterface $script
29
     */
30 510
    public function __construct($value, ScriptInterface $script)
31
    {
32
33 510
        $this->value = $value;
34 510
        $this->script = $script;
35 510
        $this
36 510
            ->initFunctionAlias('value', 'getValue')
37 510
            ->initFunctionAlias('script', 'getScript');
38 510
    }
39
40
    /**
41
     * @return void
42
     */
43
    public function __clone()
44
    {
45
        $this->script = clone $this->script;
46
    }
47
48
    /**
49
     * @see TransactionOutputInterface::getValue()
50
     */
51 396
    public function getValue()
52
    {
53 396
        return $this->value;
54
    }
55
56
    /**
57
     * @see TransactionOutputInterface::getScript()
58
     */
59 384
    public function getScript()
60
    {
61 384
        return $this->script;
62
    }
63
64
    /**
65
     * @param TransactionOutputInterface $output
66
     * @return bool
67
     */
68 12
    public function equals(TransactionOutputInterface $output)
69
    {
70 12
        $script = $this->script->equals($output->getScript());
71 12
        if (!$script) {
72 12
            return false;
73
        }
74
75 12
        return gmp_cmp($this->value, $output->getValue()) === 0;
76
    }
77
78
    /**
79
     * @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
80
     */
81 300
    public function getBuffer()
82
    {
83 300
        return (new TransactionOutputSerializer())->serialize($this);
84
    }
85
}
86