Header   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLength() 0 3 1
A getCommand() 0 3 1
A getChecksum() 0 3 1
A __construct() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Networking\Structure;
6
7
use BitWasp\Buffertools\BufferInterface;
8
9
class Header
10
{
11
    /**
12
     * @var string
13
     */
14
    private $command;
15
16
    /**
17
     * @var int
18
     */
19
    private $length;
20
21
    /**
22
     * @var BufferInterface
23
     */
24
    private $checksum;
25
26
    /**
27
     * Header constructor.
28
     * @param string $command
29
     * @param int $length
30
     * @param BufferInterface $checksum
31
     */
32
    public function __construct(string $command, int $length, BufferInterface $checksum)
33
    {
34
        if ($checksum->getSize() != 4) {
35
            throw new \InvalidArgumentException("Checksum has invalid length");
36
        }
37
38
        $this->command = $command;
39
        $this->length = $length;
40
        $this->checksum = $checksum;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getCommand(): string
47
    {
48
        return $this->command;
49
    }
50
51
    /**
52
     * @return BufferInterface
53
     */
54
    public function getChecksum(): BufferInterface
55
    {
56
        return $this->checksum;
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getLength(): int
63
    {
64
        return $this->length;
65
    }
66
}
67