Test Failed
Push — dev ( 3254b4...32905a )
by Jordan
13:46
created

ImmutableDecimal::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Samsara\Fermat\Values;
4
5
use Samsara\Fermat\Numbers;
6
use Samsara\Fermat\Types\Decimal;
7
8
class ImmutableDecimal extends Decimal
9
{
10
11
    public function modulo($mod)
12
    {
13
        $oldBase = $this->convertForModification();
14
15
        return (new ImmutableDecimal(bcmod($this->getValue(), $mod), $this->getPrecision(), $this->getBase()))->convertFromModification($oldBase);
16
    }
17
18
    public function continuousModulo($mod)
19
    {
20
21
        if (is_object($mod) && method_exists($mod, 'getPrecision')) {
22
            $precision = ($this->getPrecision() < $mod->getPrecision()) ? $mod->getPrecision() : $this->getPrecision();
23
        } else {
24
            $precision = $this->getPrecision();
25
        }
26
27
        $oldPrecision = $this->precision;
28
        $newPrecision = $precision+1;
29
30
        $this->precision = $newPrecision;
31
32
        if (is_object($mod) && method_exists($mod, 'truncateToPrecision')) {
33
            $mod = $mod->truncateToPrecision($newPrecision);
34
        } else {
35
            $mod = Numbers::make(Numbers::IMMUTABLE, $mod, $newPrecision);
36
        }
37
38
        $multiple = $this->divide($mod)->floor();
39
40
        $remainder = $this->subtract($mod->multiply($multiple));
41
42
        $this->precision = $oldPrecision;
43
44
        return $remainder->truncateToPrecision($oldPrecision);
45
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isComplex(): bool
52
    {
53
        return false;
54
    }
55
56
    /**
57
     * @param string $value
58
     *
59
     * @return ImmutableDecimal
60
     */
61
    protected function setValue(string $value)
62
    {
63
        return new ImmutableDecimal($value, $this->getPrecision(), $this->getBase());
64
    }
65
66
}