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

PingSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

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