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

PingSerializer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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