Failed Conditions
Pull Request — master (#47)
by Jordan
22:22 queued 18:21
created

ImmutableDecimal::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\Numbers;
6
use Samsara\Fermat\Types\Decimal;
7
8
class ImmutableDecimal extends Decimal
9
{
10
11 22
    public function continuousModulo($mod)
12
    {
13
14 22
        if (is_object($mod) && method_exists($mod, 'getPrecision')) {
15 21
            $precision = ($this->getPrecision() < $mod->getPrecision()) ? $mod->getPrecision() : $this->getPrecision();
16
        } else {
17 10
            $precision = $this->getPrecision();
18
        }
19
20 22
        $oldPrecision = $this->precision;
21 22
        $newPrecision = $precision+1;
22
23 22
        $this->precision = $newPrecision;
24
25 22
        if (is_object($mod) && method_exists($mod, 'truncateToPrecision')) {
26 21
            $mod = $mod->truncateToPrecision($newPrecision);
27
        } else {
28 10
            $mod = Numbers::make(Numbers::IMMUTABLE, $mod, $newPrecision);
29
        }
30
31 22
        $multiple = $this->divide($mod)->floor();
0 ignored issues
show
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

31
        $multiple = $this->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...
32
33 22
        $remainder = $this->subtract($mod->multiply($multiple));
34
35 22
        $this->precision = $oldPrecision;
36
37 22
        return $remainder->truncateToPrecision($oldPrecision);
0 ignored issues
show
Bug introduced by
The method truncateToPrecision() 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

37
        return $remainder->/** @scrutinizer ignore-call */ truncateToPrecision($oldPrecision);

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 truncateToPrecision() 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

37
        return $remainder->/** @scrutinizer ignore-call */ truncateToPrecision($oldPrecision);

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...
38
39
    }
40
41
    /**
42
     * @return bool
43
     */
44 59
    public function isComplex(): bool
45
    {
46 59
        return false;
47
    }
48
49
    /**
50
     * @param string $value
51
     * @param int $precision
52
     * @param int $base
53
     *
54
     * @return ImmutableDecimal
55
     */
56 75
    protected function setValue(string $value, int $precision = null, int $base = 10)
57
    {
58 75
        $imaginary = false;
59
60 75
        if (strpos($value, 'i') !== false) {
61 7
            $value = str_replace('i', '', $value);
62 7
            $imaginary = true;
63
        }
64
65 75
        if ($base != 10 || $this->getBase() != 10) {
66 3
            $base = $base == 10 ? $this->getBase() : $base;
67 3
            $value = $this->convertValue($value, 10, $base);
68
        }
69
70 75
        if ($imaginary) {
71 7
            $value .= 'i';
72
        }
73
74 75
        if (is_null($precision)) {
75 68
            $precision = $this->getPrecision();
76
        }
77
78 75
        return new ImmutableDecimal($value, $precision, $base);
79
    }
80
81
}