Passed
Pull Request — master (#89)
by thomas
02:12
created

PongSerializer::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
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\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
        $nonce = (int) $this->uint64->read($parser);
41
        return new Pong($nonce);
42
    }
43
44
    /**
45
     * @param BufferInterface $data
46 3
     * @return Pong
47
     */
48 3
    public function parse(BufferInterface $data): Pong
49
    {
50
        return $this->fromParser(new Parser($data));
51
    }
52
}
53