RandomIntegerGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A below() 0 6 2
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