StochasticAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0
eloc 16
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A determineCarry() 0 21 3
1
<?php
2
3
namespace Samsara\Fermat\Core\Provider\RoundingModeAdapters\Modes;
4
5
use Samsara\Fermat\Core\Enums\RandomMode;
6
use Samsara\Fermat\Core\Provider\RandomProvider;
7
8
/**
9
 *
10
 */
11
class StochasticAdapter extends BaseAdapter
12
{
13
14
    /**
15
     * @inheritDoc
16
     */
17 2
    public function determineCarry(int $digit, int $nextDigit): int
18
    {
19 2
        $remainder = $this->remainder;
20
21 2
        if (is_null($remainder)) {
22 2
            $target = $digit;
23 2
            $rangeMin = 0;
24 2
            $rangeMax = 9;
25
        } else {
26
            $remainder = substr($remainder, 0, 3);
27
            $target = (int)($digit.$remainder);
28
            $rangeMin = 0;
29
            $rangeMax = (int)str_repeat('9', strlen($remainder) + 1);
30
        }
31
32 2
        $random = RandomProvider::randomInt($rangeMin, $rangeMax, RandomMode::Speed)->asInt();
33
34 2
        if ($random < $target) {
35 2
            return 1;
36
        } else {
37 2
            return 0;
38
        }
39
    }
40
}