PredefinedIntegerGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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