Completed
Pull Request — master (#81)
by thomas
02:07
created

Header::getLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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