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.

MajorityQuorum::isMet()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 8
nc 3
nop 1
crap 4
1
<?php
2
3
namespace RemiSan\Lock\Quorum;
4
5
use RemiSan\Lock\Quorum;
6
7
class MajorityQuorum implements Quorum
8
{
9
    /**
10
     * @var int
11
     */
12
    private $total;
13
14
    /**
15
     * @var int
16
     */
17
    private $quorum = null;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 21
    public function init($totalNumber)
23
    {
24 21
        if ($totalNumber < 1) {
25 3
            throw new \InvalidArgumentException('You must have at least one store.');
26
        }
27
28 18
        $this->total = $totalNumber;
29 18
        $this->quorum = (int) floor($totalNumber / 2) + 1;
30 18
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 21
    public function isMet($numberOfSuccess)
36
    {
37 21
        if ($this->quorum === null) {
38 3
            throw new \RuntimeException('You must init the Quorum before querying it.');
39
        }
40
41 18
        if ($numberOfSuccess < 0 ||
42 18
            $numberOfSuccess > $this->total) {
43 6
            throw new \InvalidArgumentException(
44 2
                'Number of success cannot be inferior to zero or superior to the number of stores.'
45 4
            );
46
        }
47
48 12
        return $numberOfSuccess >= $this->quorum;
49
    }
50
}
51