Passed
Push — master ( 3dc4f8...535c32 )
by thomas
15:05
created

PongSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 13
cts 13
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 __construct() 0 3 1
A parse() 0 3 1
A fromParser() 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\Pong;
8
use BitWasp\Bitcoin\Serializer\Types;
9
use BitWasp\Buffertools\Buffer;
10
use BitWasp\Buffertools\BufferInterface;
11
use BitWasp\Buffertools\Parser;
12
13
class PongSerializer
14 9
{
15
    /**
16 9
     * @var \BitWasp\Buffertools\Types\Uint64
17 9
     */
18 9
    private $uint64;
19
20
    public function __construct()
21
    {
22
        $this->uint64 = Types::uint64();
23
    }
24
25 9
    /**
26
     * @param Pong $pong
27 9
     * @return BufferInterface
28 9
     */
29 6
    public function serialize(Pong $pong): BufferInterface
30
    {
31
        return new Buffer($this->uint64->write($pong->getNonce()));
32
    }
33
34
    /**
35
     * @param Parser $parser
36 3
     * @return Pong
37
     */
38 3
    public function fromParser(Parser $parser): Pong
39 3
    {
40
        return new Pong((int) $this->uint64->read($parser));
41
    }
42
43
    /**
44
     * @param BufferInterface $data
45
     * @return Pong
46 3
     */
47
    public function parse(BufferInterface $data): Pong
48 3
    {
49
        return $this->fromParser(new Parser($data));
50
    }
51
}
52