BitMask::getBitMasks()   A
last analyzed

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 PhpBinaryReader;
4
5
use PhpBinaryReader\Exception\InvalidDataException;
6
7
class BitMask
8
{
9
    const MASK_LO = 0;
10
    const MASK_HI = 1;
11
12
    /**
13
     * @var array
14
     */
15
    private $bitMasks = [
16
        [0x00, 0xFF],
17
        [0x01, 0x7F],
18
        [0x03, 0x3F],
19
        [0x07, 0x1F],
20
        [0x0F, 0x0F],
21
        [0x1F, 0x07],
22
        [0x3F, 0x03],
23
        [0x7F, 0x01],
24
        [0xFF, 0x00]
25
    ];
26
27
    /**
28
     * @return array
29
     */
30 69
    public function getBitMasks()
31
    {
32 69
        return $this->bitMasks;
33
    }
34
35
    /**
36
     * @param  int                            $bit
37
     * @param  int                            $type
38
     * @return mixed
39
     * @throws Exception\InvalidDataException
40
     */
41 69
    public function getMask($bit, $type)
42
    {
43 69
        $bit = (int) $bit >= 0 && (int) $bit <= 8 ? $bit : 0;
44
45 69
        if ($type == self::MASK_LO) {
46 67
            return $this->getBitMasks()[$bit][self::MASK_LO];
47 18
        } elseif ($type == self::MASK_HI) {
48 17
            return $this->getBitMasks()[$bit][self::MASK_HI];
49
        } else {
50 1
            throw new InvalidDataException('You can only request a lo or hi bit mask using this method');
51
        }
52
    }
53
}
54