BitStreamReader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
dl 0
loc 34
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readBit() 0 9 2
A isEOF() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Mfonte\Base62x\Compression\Huffman\Binary;
4
5
/**
6
 *	turns string data into a stream of bits.
7
 */
8
class BitStreamReader
9
{
10
    private $dataArray = null;
11
    private $cursor = 0;
12
13
    /**
14
     *	To initialize, provide string data containing the bits.
15
     */
16
    public function __construct($data)
17
    {
18
        $this->dataArray = BitArray::load($data);
19
    }
20
21
    /**
22
     *	read one bit at a time from the buffer, returning null for EOF.
23
     */
24
    public function readBit()
25
    {
26
        if ($this->isEOF()) {
27
            return null;
28
        } else {
29
            $bit = $this->dataArray[$this->cursor];
30
            ++$this->cursor;
31
32
            return $bit;
33
        }
34
    }
35
36
    /**
37
     *	whether we've reached the end of our data.
38
     */
39
    public function isEOF()
40
    {
41
        return !$this->dataArray->offsetExists($this->cursor);
42
    }
43
}
44