Completed
Push — master ( 2dcc62...2dcc62 )
by thomas
151:35 queued 116:37
created

Header::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
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
    public function __construct($command, $length, BufferInterface $checksum)
31
    {
32
        if ($checksum->getSize() != 4) {
33
            throw new \InvalidArgumentException("Checksum has invalid length");
34
        }
35
36
        $this->command = $command;
37
        $this->length = $length;
38
        $this->checksum = $checksum;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getCommand()
45
    {
46
        return $this->command;
47
    }
48
49
    /**
50
     * @return BufferInterface
51
     */
52
    public function getChecksum()
53
    {
54
        return $this->checksum;
55
    }
56
57
    /**
58
     * @return int
59
     */
60
    public function getLength()
61
    {
62
        return $this->length;
63
    }
64
}
65