Passed
Push — master ( 532106...9e740c )
by thomas
16:39
created

PingSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
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\Buffertools\BufferInterface;
9
use BitWasp\Buffertools\Parser;
10
11
class PingSerializer
12
{
13
    /**
14 12
     * @param Ping $ping
15
     * @return BufferInterface
16 12
     */
17 12
    public function serialize(Ping $ping): BufferInterface
18 12
    {
19
        return $ping->getNonce();
20
    }
21
22
    /**
23
     * @param Parser $parser
24
     * @return Ping
25 9
     */
26
    public function fromParser(Parser $parser): Ping
27 9
    {
28 9
        return new Ping($parser->readBytes(8));
29 6
    }
30
31
    /**
32
     * @param BufferInterface $data
33
     * @return Ping
34
     */
35
    public function parse(BufferInterface $data): Ping
36 6
    {
37
        return $this->fromParser(new Parser($data));
38 6
    }
39
}
40