Failed Conditions
Push — dev ( 51d7f8...8abba3 )
by Jordan
13:12
created

MutableDecimal::modulo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
    public function continuousModulo($mod)
12
    {
13
14
        $mod = Numbers::makeOrDont(Numbers::IMMUTABLE, $mod, $this->precision+1);
15
        $oldNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(), $this->precision+1);
16
17
        $multiple = $oldNum->divide($mod)->floor();
0 ignored issues
show
Bug introduced by
The method floor() does not exist on Samsara\Fermat\Types\Bas...Numbers\NumberInterface. It seems like you code against a sub-type of Samsara\Fermat\Types\Bas...Numbers\NumberInterface such as Samsara\Fermat\Types\Bas...umbers\DecimalInterface or Samsara\Fermat\Types\Decimal. ( Ignorable by Annotation )

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

17
        $multiple = $oldNum->divide($mod)->/** @scrutinizer ignore-call */ floor();
Loading history...
Bug introduced by
The method floor() does not exist on Samsara\Fermat\Types\Bas...mbers\FractionInterface. ( Ignorable by Annotation )

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

17
        $multiple = $oldNum->divide($mod)->/** @scrutinizer ignore-call */ floor();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method floor() does not exist on Samsara\Fermat\Values\ImmutableComplexNumber. ( Ignorable by Annotation )

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

17
        $multiple = $oldNum->divide($mod)->/** @scrutinizer ignore-call */ floor();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
19
        $remainder = $oldNum->subtract($mod->multiply($multiple));
20
21
        return Numbers::make(Numbers::MUTABLE, $remainder->truncate($this->precision)->getValue());
0 ignored issues
show
Bug introduced by
The method truncate() does not exist on Samsara\Fermat\Types\Bas...Numbers\NumberInterface. It seems like you code against a sub-type of Samsara\Fermat\Types\Bas...Numbers\NumberInterface such as Samsara\Fermat\Types\Bas...umbers\DecimalInterface or Samsara\Fermat\Types\Decimal. ( Ignorable by Annotation )

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

21
        return Numbers::make(Numbers::MUTABLE, $remainder->/** @scrutinizer ignore-call */ truncate($this->precision)->getValue());
Loading history...
Bug Best Practice introduced by
The expression return Samsara\Fermat\Nu...precision)->getValue()) also could return the type Samsara\Fermat\Types\Bas...\Values\MutableFraction which is incompatible with the return type mandated by Samsara\Fermat\Types\Bas...ace::continuousModulo() of Samsara\Fermat\Types\Bas...umbers\DecimalInterface.
Loading history...
Bug introduced by
The method truncate() does not exist on Samsara\Fermat\Values\ImmutableComplexNumber. ( Ignorable by Annotation )

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

21
        return Numbers::make(Numbers::MUTABLE, $remainder->/** @scrutinizer ignore-call */ truncate($this->precision)->getValue());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method truncate() does not exist on Samsara\Fermat\Types\Bas...mbers\FractionInterface. ( Ignorable by Annotation )

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

21
        return Numbers::make(Numbers::MUTABLE, $remainder->/** @scrutinizer ignore-call */ truncate($this->precision)->getValue());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
23
    }
24
25
    /**
26
     * @param string $value
27
     *
28
     * @return MutableDecimal
29
     */
30
    protected function setValue(string $value, int $precision = null, int $base = 10)
31
    {
32
        $imaginary = false;
33
34
        if (strpos($value, 'i') !== false) {
35
            $value = str_replace('i', '', $value);
36
            $imaginary = true;
37
        }
38
39
        if ($base != 10) {
40
            $value = $this->convertValue($value, 10, $base);
41
        }
42
43
        if ($imaginary) {
44
            $value .= 'i';
45
        }
46
47
        if (is_null($precision)) {
48
            $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
        $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
        return $this;
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function isComplex(): bool
60
    {
61
        return false;
62
    }
63
64
}