InvSerializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 3 1
A fromParser() 0 4 1
A __construct() 0 3 1
A parse() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Networking\Serializer\Message;
6
7
use BitWasp\Bitcoin\Networking\Messages\Inv;
8
use BitWasp\Bitcoin\Networking\Serializer\Structure\InventorySerializer;
9
use BitWasp\Bitcoin\Serializer\Types;
10
use BitWasp\Buffertools\Buffer;
11
use BitWasp\Buffertools\BufferInterface;
12
use BitWasp\Buffertools\Parser;
13
use BitWasp\Buffertools\Types\Vector;
14
15
class InvSerializer
16
{
17
    /**
18
     * @var Vector
19
     */
20 96
    private $vectorInventory;
21
22 96
    /**
23 96
     * @param InventorySerializer $invVector
24
     */
25
    public function __construct(InventorySerializer $invVector)
26
    {
27
        $this->vectorInventory = Types::vector([$invVector, 'fromParser']);
28 3
    }
29
30 3
    /**
31 3
     * @param Parser $parser
32 3
     * @return Inv
33 3
     */
34 3
    public function fromParser(Parser $parser): Inv
35
    {
36
        $items = $this->vectorInventory->read($parser);
37
        return new Inv($items);
38
    }
39
40
    /**
41 3
     * @param BufferInterface $data
42
     * @return Inv
43 3
     */
44 3
    public function parse(BufferInterface $data): Inv
45
    {
46
        return $this->fromParser(new Parser($data));
47
    }
48
49
    /**
50
     * @param Inv $inv
51 3
     * @return BufferInterface
52
     */
53 3
    public function serialize(Inv $inv): BufferInterface
54
    {
55
        return new Buffer($this->vectorInventory->write($inv->getItems()));
56
    }
57
}
58