RandomIntegerGenerator::below()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Random;
4
5
use RuntimeException;
6
use function random_int;
7
8
final class RandomIntegerGenerator implements IntegerGenerator
9
{
10
    public static function make(): self
11
    {
12
        return new self();
13
    }
14
15
    public function below(int $number): int
16
    {
17
        if ($number < 1) {
18
            throw new RuntimeException('Not generating negative numbers');
19
        }
20
        return random_int(0, $number - 1);
21
    }
22
}
23