Pong   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getNonce() 0 3 1
A getNetworkCommand() 0 3 1
A getBuffer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Networking\Messages;
6
7
use BitWasp\Bitcoin\Networking\Message;
8
use BitWasp\Bitcoin\Networking\NetworkSerializable;
9
use BitWasp\Bitcoin\Networking\Serializer\Message\PongSerializer;
10
use BitWasp\Buffertools\BufferInterface;
11
12
class Pong extends NetworkSerializable
13
{
14
    /**
15
     * @var BufferInterface
16
     */
17
    private $nonce;
18
19 9
    /**
20
     * @param BufferInterface $nonce
21 9
     */
22 9
    public function __construct(BufferInterface $nonce)
23
    {
24
        if ($nonce->getSize() !== 8) {
25
            throw new \RuntimeException("Invalid nonce size");
26
        }
27 9
        $this->nonce = $nonce;
28
    }
29 9
30
    /**
31
     * @return string
32
     * @see https://en.bitcoin.it/wiki/Protocol_documentation#pong
33
     */
34
    public function getNetworkCommand(): string
35 9
    {
36
        return Message::PONG;
37 9
    }
38
39
    /**
40
     * @return BufferInterface
41
     */
42
    public function getNonce(): BufferInterface
43 9
    {
44
        return $this->nonce;
45 9
    }
46
47
    /**
48
     * @return BufferInterface
49
     */
50
    public function getBuffer(): BufferInterface
51
    {
52
        return (new PongSerializer())->serialize($this);
53
    }
54
}
55