Completed
Push — master ( 2683bd...cf87f7 )
by Jordan
21s queued 13s
created

HalfRandomAdapter::determineCarry()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.583

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 9
ccs 5
cts 7
cp 0.7143
crap 5.583
rs 9.6111
1
<?php
2
3
namespace Samsara\Fermat\Provider\RoundingModeAdapters\Modes;
4
5
use Samsara\Fermat\Enums\RandomMode;
6
use Samsara\Fermat\Provider\RandomProvider;
7
8
/**
9
 *
10
 */
11
class HalfRandomAdapter extends BaseAdapter
12
{
13
14
    /**
15
     * @inheritDoc
16
     */
17 1
    public function determineCarry(int $digit, int $nextDigit): int
18
    {
19 1
        $early = static::nonHalfEarlyReturn($digit);
20 1
        $remainder = $this->remainderCheck();
21
22 1
        if ($early == 0 && !$remainder) {
23 1
            return RandomProvider::randomInt(0, 1, RandomMode::Speed)->asInt();
24
        } else {
25
            return (($early == 1 || $remainder) ? 1 : 0);
26
        }
27
    }
28
}