Completed
Pull Request — master (#81)
by thomas
35:05
created

Header   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getCommand() 0 4 1
A getChecksum() 0 4 1
A getLength() 0 4 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
    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