HalfRandomAdapter::determineCarry()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.1158

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
crap 5.1158
rs 9.6111
c 0
b 0
f 0
eloc 6
nc 5
nop 2
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 HalfRandomAdapter extends BaseAdapter
12
{
13
14
    /**
15
     * @inheritDoc
16
     */
17 2
    public function determineCarry(int $digit, int $nextDigit): int
18
    {
19 2
        $early = static::nonHalfEarlyReturn($digit);
20 2
        $remainder = $this->remainderCheck();
21
22 2
        if ($early == 0 && !$remainder) {
23 2
            return RandomProvider::randomInt(0, 1, RandomMode::Speed)->asInt();
24
        } else {
25
            return (($early == 1 || $remainder) ? 1 : 0);
26
        }
27
    }
28
}