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

BaseAdapter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 60
ccs 14
cts 14
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A remainderCheck() 0 9 2
A setNegative() 0 5 1
A nonHalfEarlyReturn() 0 3 1
A __construct() 0 1 1
A setRemainder() 0 5 1
1
<?php
2
3
namespace Samsara\Fermat\Provider\RoundingModeAdapters\Modes;
4
5
/**
6
 *
7
 */
8
abstract class BaseAdapter
9
{
10
11
    /**
12
     * @param bool $isNegative
13
     * @param string|null $remainder
14
     */
15 13
    public function __construct(protected bool $isNegative, protected ?string $remainder) {}
16
17
    /**
18
     * @param bool $isNegative
19
     * @return $this
20
     */
21 854
    public function setNegative(bool $isNegative): BaseAdapter
22
    {
23 854
        $this->isNegative = $isNegative;
24
25 854
        return $this;
26
    }
27
28
    /**
29
     * @param string|null $remainder
30
     * @return $this
31
     */
32 854
    public function setRemainder(?string $remainder): BaseAdapter
33
    {
34 854
        $this->remainder = $remainder;
35
36 854
        return $this;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42 820
    protected function remainderCheck(): bool
43
    {
44 820
        if (is_null($this->remainder)) {
45 775
            return false;
46
        }
47
48 203
        $remainder = str_replace('0', '', $this->remainder);
49
50 203
        return !empty($remainder);
51
    }
52
53
    /**
54
     * @param int $digit
55
     * @return int
56
     */
57 774
    protected static function nonHalfEarlyReturn(int $digit): int
58
    {
59 774
        return $digit <=> 5;
60
    }
61
62
    /**
63
     * @param int $digit
64
     * @param int $nextDigit
65
     * @return int
66
     */
67
    abstract public function determineCarry(int $digit, int $nextDigit): int;
68
69
}