GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6fd524...ba304a )
by Maximilian
07:36
created

IntBitField   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A set() 0 8 1
A guardAgainstBounds() 0 6 4
A has() 0 8 1
1
<?php
2
3
namespace maxwilms\BloomFilter;
4
5
class IntBitField implements BitField
6
{
7
    const C = 32; // on 64-bit machines this value can be 64, on 32-bit it needs to be 32.
8
    protected $length;
9
    protected $data;
10
11
    public function __construct($length)
12
    {
13
        $this->length = $length;
14
15
        $this->data = [];
16
        $cells = ceil($this->length / self::C);
17
        for ($i = 0; $i < $cells; $i++) {
18
            $this->data[$i] = 0;
19
        }
20
    }
21
22
    /**
23
     * @param integer $bit set the bit
24
     * @throws \InvalidArgumentException
25
     */
26
    public function set($bit)
27
    {
28
        $this->guardAgainstBounds($bit);
29
30
        $index = (int)($bit / self::C);
31
32
        $this->data[$index] = $this->data[$index] | (1 << $bit % self::C);
33
    }
34
35
    /**
36
     * @param $bit
37
     * @throws \InvalidArgumentException
38
     */
39
    protected function guardAgainstBounds($bit)
40
    {
41
        if ($bit < 0 || $bit >= $this->length || intval($bit) !== $bit) {
42
            throw new \InvalidArgumentException('Out of bounds.');
43
        }
44
    }
45
46
    /**
47
     * @param integer $bit check if bit is set
48
     * @return bool
49
     * @throws \InvalidArgumentException
50
     */
51
    public function has($bit)
52
    {
53
        $this->guardAgainstBounds($bit);
54
55
        $index = (int)($bit / self::C);
56
57
        return ($this->data[$index] & (1 << $bit % self::C)) !== 0;
58
    }
59
}
60