Completed
Push — master ( 4ca74a...73e746 )
by thomas
14s
created

TransactionOutput   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 81.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 63
ccs 13
cts 16
cp 0.8125
rs 10
c 1
b 0
f 0
wmc 6
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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 2668
    public function __construct($value, ScriptInterface $script)
29
    {
30 2668
        $this->value = $value;
31 2668
        $this->script = $script;
32 2668
    }
33
34
    /**
35
     * @see TransactionOutputInterface::getValue()
36
     */
37
    public function getValue()
38
    {
39
        return $this->value;
40
    }
41
42
    /**
43
     * @see TransactionOutputInterface::getScript()
44
     */
45 2818
    public function getScript()
46
    {
47 2818
        return $this->script;
48
    }
49
50
    /**
51
     * @param TransactionOutputInterface $output
52
     * @return bool
53 2806
     */
54
    public function equals(TransactionOutputInterface $output)
55 2806
    {
56
        $script = $this->script->equals($output->getScript());
57
        if (!$script) {
58
            return false;
59
        }
60
61
        return gmp_cmp($this->value, $output->getValue()) === 0;
62 48
    }
63
64 48
    /**
65 48
     * @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
66 12
     */
67
    public function getBuffer()
68
    {
69 48
        return (new TransactionOutputSerializer())->serialize($this);
70
    }
71
}
72