Passed
Push — dev ( 1fc0f3...09846b )
by Jordan
42s queued 10s
created

MutableNumber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A modulo() 0 5 1
A setValue() 0 5 1
A continuousModulo() 0 11 1
1
<?php
2
3
namespace Samsara\Fermat\Values;
4
5
use Samsara\Fermat\Types\Number;
6
use Samsara\Fermat\Types\Base\DecimalInterface;
7
use Samsara\Fermat\Types\Base\NumberInterface;
8
use Samsara\Fermat\Numbers;
9
10
class MutableNumber extends Number implements NumberInterface, DecimalInterface
11
{
12
13 1
    public function modulo($mod)
14
    {
15 1
        $oldBase = $this->convertForModification();
16
17 1
        return (new MutableNumber(bcmod($this->getValue(), $mod), $this->getPrecision()))->convertFromModification($oldBase);
18
    }
19
20 1
    public function continuousModulo($mod)
21
    {
22
23 1
        $mod = Numbers::makeOrDont(Numbers::IMMUTABLE, $mod, $this->precision+1);
24 1
        $oldNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(), $this->precision+1);
25
26 1
        $multiple = $oldNum->divide($mod)->floor();
27
28 1
        $remainder = $oldNum->subtract($mod->multiply($multiple));
29
30 1
        return Numbers::make(Numbers::MUTABLE, $remainder->truncate($this->precision)->getValue());
31
32
    }
33
34
    /**
35
     * @param $value
36
     *
37
     * @return MutableNumber
38
     */
39 2
    protected function setValue($value)
40
    {
41 2
        $this->value = $value;
42
43 2
        return $this;
44
    }
45
46
}