Failed Conditions
Pull Request — master (#47)
by Jordan
07:14 queued 03:12
created

MutableDecimal   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 54
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 24 5
A isComplex() 0 3 1
A continuousModulo() 0 11 1
1
<?php
2
3
namespace Samsara\Fermat\Values;
4
5
use Samsara\Fermat\Types\Decimal;
6
use Samsara\Fermat\Numbers;
7
8
class MutableDecimal extends Decimal
9
{
10
11 1
    public function continuousModulo($mod)
12
    {
13
14 1
        $mod = Numbers::makeOrDont(Numbers::IMMUTABLE, $mod, $this->precision+1);
15 1
        $oldNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(), $this->precision+1);
16
17 1
        $multiple = $oldNum->divide($mod)->floor();
18
19 1
        $remainder = $oldNum->subtract($mod->multiply($multiple));
20
21 1
        return Numbers::make(Numbers::MUTABLE, $remainder->truncate($this->precision)->getValue());
22
23
    }
24
25
    /**
26
     * @param string $value
27
     *
28
     * @return MutableDecimal
29
     */
30 3
    protected function setValue(string $value, int $precision = null, int $base = 10)
31
    {
32 3
        $imaginary = false;
33
34 3
        if (strpos($value, 'i') !== false) {
35
            $value = str_replace('i', '', $value);
36
            $imaginary = true;
37
        }
38
39 3
        if ($base != 10) {
40
            $value = $this->convertValue($value, 10, $base);
41
        }
42
43 3
        if ($imaginary) {
44
            $value .= 'i';
45
        }
46
47 3
        if (is_null($precision)) {
48 1
            $precision = $this->getPrecision();
0 ignored issues
show
Unused Code introduced by
The assignment to $precision is dead and can be removed.
Loading history...
49
        }
50
51 3
        $this->value = $this->translateValue($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type false; however, parameter $value of Samsara\Fermat\Types\Decimal::translateValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $this->value = $this->translateValue(/** @scrutinizer ignore-type */ $value);
Loading history...
52
53 3
        return $this;
54
    }
55
56
    /**
57
     * @return bool
58
     */
59 2
    public function isComplex(): bool
60
    {
61 2
        return false;
62
    }
63
64
}