PredefinedIntegerGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A below() 0 9 2
A __construct() 0 3 1
A generating() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Random;
4
5
use RuntimeException;
6
use function sprintf;
7
8
final class PredefinedIntegerGenerator implements IntegerGenerator
9
{
10
    /** @var int */
11
    private $number;
12
13
    public function __construct(int $number)
14
    {
15
        $this->number = $number;
16
    }
17
18
    public static function generating(int $number): self
19
    {
20
        return new self($number);
21
    }
22
23
    public function below(int $number): int
24
    {
25
        if ($this->number < $number) {
26
            return $this->number;
27
        }
28
        throw new RuntimeException(sprintf(
29
            'Cannot generate a number: %d is not below %d',
30
            $this->number,
31
            $number
32
        ));
33
    }
34
}
35