Passed
Pull Request — main (#1)
by Anatolyi
10:58
created

FairRNG   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gambling\Tech\Game;
6
7
use Gambling\Tech\Dice\RngTillHundred;
8
use Gambling\Tech\Exception\GamblingTechException;
9
use Gambling\Tech\Exception\InvalidArgumentException;
10
11
class FairRNG
12
{
13
    private SeedPairGenerator $seedPairGenerator;
14
15
    /**
16
     * @param SeedPairGenerator $seedPairGenerator
17
     */
18
    public function __construct(SeedPairGenerator $seedPairGenerator)
19
    {
20
        $this->seedPairGenerator = $seedPairGenerator;
21
    }
22
23
    /**
24
     * @param object $condition
25
     * @return LuckyNumber
26
     * @throws GamblingTechException
27
     * @throws InvalidArgumentException
28
     */
29
    public function __invoke(object $condition): LuckyNumber
30
    {
31
        $seedPair = $this->seedPairGenerator->getCurrentSeedPairOrGenerate($condition);
32
33
        $seedPair = SeedPair::increment($seedPair);
34
35
        $luckyNumber = (new RngTillHundred())(
36
            $seedPair->getServerSeed(),
37
            $seedPair->getClientSeed(),
38
            $seedPair->getNonce()
39
        );
40
41
        return new LuckyNumber($luckyNumber, $seedPair);
42
    }
43
}
44