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

FairRNG::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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