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

HalfAlternatingAdapter::determineCarry()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.2742

Importance

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