Completed
Push — master ( bb8b5d...7f2cd3 )
by thomas
23:00
created

OutPointSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A serialize() 0 7 1
A fromParser() 0 4 1
A parse() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Serializer\Transaction;
4
5
use BitWasp\Bitcoin\Serializer\Types;
6
use BitWasp\Bitcoin\Transaction\OutPoint;
7
use BitWasp\Bitcoin\Transaction\OutPointInterface;
8
use BitWasp\Buffertools\Buffer;
9
use BitWasp\Buffertools\BufferInterface;
10
use BitWasp\Buffertools\Parser;
11
12
class OutPointSerializer implements OutPointSerializerInterface
13
{
14
    /**
15
     * @var \BitWasp\Buffertools\Types\ByteString
16
     */
17
    private $txid;
18
19
    /**
20
     * @var \BitWasp\Buffertools\Types\Uint32
21
     */
22
    private $vout;
23
24 1338
    public function __construct()
25
    {
26 1338
        $this->txid = Types::bytestringle(32);
27 1338
        $this->vout = Types::uint32le();
28 1338
    }
29
30
    /**
31
     * @param OutPointInterface $outpoint
32
     * @return BufferInterface
33
     */
34 1308
    public function serialize(OutPointInterface $outpoint)
35
    {
36 1308
        return new Buffer(
37 1308
            $this->txid->write($outpoint->getTxId()) .
38 1308
            $this->vout->write($outpoint->getVout())
39
        );
40
    }
41
42
    /**
43
     * @param Parser $parser
44
     * @return OutPointInterface
45
     */
46 68
    public function fromParser(Parser $parser)
47
    {
48 68
        return new OutPoint($this->txid->read($parser), $this->vout->read($parser));
49
    }
50
51
    /**
52
     * @param string|\BitWasp\Buffertools\BufferInterface $data
53
     * @return OutPointInterface
54
     */
55 2
    public function parse($data)
56
    {
57 2
        return $this->fromParser(new Parser($data));
58
    }
59
}
60