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.

IntBitField::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 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