Passed
Pull Request — dev (#56)
by Jordan
08:50
created

MutableDecimal::isComplex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
use Samsara\Fermat\Types\Base\Interfaces\Numbers\DecimalInterface;
8
9
class MutableDecimal extends Decimal
10
{
11
12 1
    public function continuousModulo($mod): DecimalInterface
13
    {
14
15 1
        $mod = Numbers::makeOrDont(Numbers::IMMUTABLE, $mod, $this->precision+1);
16 1
        $oldNum = Numbers::make(Numbers::IMMUTABLE, $this->getValue(), $this->precision+1);
17
18 1
        $multiple = $oldNum->divide($mod)->floor();
0 ignored issues
show
Bug introduced by
The method floor() does not exist on Samsara\Fermat\Values\MutableFraction. ( Ignorable by Annotation )

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

18
        $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\ImmutableFraction. ( Ignorable by Annotation )

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

18
        $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...
19
20 1
        $remainder = $oldNum->subtract($mod->multiply($multiple));
21
22 1
        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\Values\MutableFraction. ( Ignorable by Annotation )

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

22
        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 Best Practice introduced by
The expression return Samsara\Fermat\Nu...precision)->getValue()) could return the type Samsara\Fermat\Values\Im...\Values\MutableFraction which is incompatible with the type-hinted return Samsara\Fermat\Types\Bas...umbers\DecimalInterface. Consider adding an additional type-check to rule them out.
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

22
        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...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

22
        return Numbers::make(Numbers::MUTABLE, $remainder->/** @scrutinizer ignore-call */ truncate($this->precision)->getValue());
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

22
        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\Values\ImmutableFraction. ( Ignorable by Annotation )

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

22
        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...
23
24
    }
25
26
    /**
27
     * @param string $value
28
     *
29
     * @return MutableDecimal
30
     */
31 10
    protected function setValue(string $value, int $precision = null, int $base = 10)
32
    {
33 10
        $imaginary = false;
34
35 10
        if (strpos($value, 'i') !== false) {
36
            $value = str_replace('i', '', $value);
37
            $imaginary = true;
38
        }
39
40 10
        if ($base != 10) {
41
            $value = $this->convertValue($value, 10, $base);
42
        }
43
44 10
        if ($imaginary) {
45
            $value .= 'i';
46
        }
47
48 10
        if (is_null($precision)) {
49 9
            $this->precision = $this->getPrecision();
50
        }
51
52 10
        $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

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