Completed
Pull Request — dev (#23)
by Jordan
02:47
created

StatsProvider::gammaFunction()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 41
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 0
cts 32
cp 0
rs 8.439
c 0
b 0
f 0
cc 6
eloc 23
nc 5
nop 2
crap 42
1
<?php
2
3
namespace Samsara\Fermat\Provider;
4
5
use Samsara\Exceptions\UsageError\IntegrityConstraint;
6
use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
7
use Samsara\Fermat\Numbers;
8
use Samsara\Fermat\Types\Base\NumberInterface;
9
use Samsara\Fermat\Types\Base\DecimalInterface;
10
use Samsara\Fermat\Types\Base\FractionInterface;
11
use Samsara\Fermat\Values\ImmutableNumber;
12
13
class StatsProvider
14
{
15
16
    /**
17
     * @param $x
18
     *
19
     * @return NumberInterface
20
     * @throws IntegrityConstraint
21
     */
22
    public static function normalCDF($x)
23
    {
24
        $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x);
25
26
        $pi = Numbers::makePi();
27
        $e = Numbers::makeE();
28
        $one = Numbers::makeOne();
29
30
        $eExponent = Numbers::make(Numbers::IMMUTABLE, $x->getValue());
0 ignored issues
show
Bug introduced by
The method getValue does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
31
        $eExponent->pow(2)->divide(2)->multiply(-1);
0 ignored issues
show
Bug introduced by
The method pow does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
33
        $answer = Numbers::make(Numbers::IMMUTABLE, 0.5);
34
        $answer = $answer->add(
0 ignored issues
show
Bug introduced by
The method add does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
35
            $one->divide($pi->multiply(2)->sqrt())
0 ignored issues
show
Bug introduced by
The method sqrt does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method multiply does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Base\DecimalInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
                ->multiply($e->pow($eExponent))
37
                ->multiply(SeriesProvider::maclaurinSeries(
38
                    $x,
0 ignored issues
show
Bug introduced by
It seems like $x defined by \Samsara\Fermat\Numbers:...Numbers::IMMUTABLE, $x) on line 24 can also be of type array or object<Samsara\Fermat\Ty...se\CoordinateInterface> or object<Samsara\Fermat\Ty...\Base\DecimalInterface> or object<Samsara\Fermat\Ty...Base\FractionInterface>; however, Samsara\Fermat\Provider\...ider::maclaurinSeries() does only seem to accept object<Samsara\Fermat\Types\Base\NumberInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39
                    function ($n) {
0 ignored issues
show
Unused Code introduced by
The parameter $n is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
                        return Numbers::makeOne();
41
                    },
42
                    function ($n) {
43
                        return SequenceProvider::nthOddNumber($n);
44
                    },
45
                    function ($n) {
46
                        return SequenceProvider::nthOddNumber($n)->doubleFactorial();
0 ignored issues
show
Bug introduced by
The method doubleFactorial does only exist in Samsara\Fermat\Types\Base\DecimalInterface, but not in Samsara\Fermat\Types\Base\NumberInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
                    }
48
                ))
49
        );
50
51
        return $answer;
52
53
    }
54
55
    /**
56
     * @param $x
57
     *
58
     * @return DecimalInterface|NumberInterface
59
     * @throws IntegrityConstraint
60
     */
61
    public static function complementNormalCDF($x)
62
    {
63
        $p = self::normalCDF($x);
64
        $one = Numbers::makeOne();
65
66
        return $one->subtract($p);
67
    }
68
69
    /**
70
     * @param $x
71
     *
72
     * @return DecimalInterface|FractionInterface|NumberInterface|ImmutableNumber
73
     * @throws IntegrityConstraint
74
     */
75
    public static function gaussErrorFunction($x)
76
    {
77
78
        $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x);
79
        $answer = Numbers::makeOne();
80
        $pi = Numbers::makePi();
81
82
        $answer = $answer->multiply(2)->divide($pi->sqrt());
0 ignored issues
show
Bug introduced by
The method divide does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Base\DecimalInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
83
84
        $answer = $answer->multiply(
85
            SeriesProvider::maclaurinSeries(
86
                $x,
0 ignored issues
show
Bug introduced by
It seems like $x defined by \Samsara\Fermat\Numbers:...Numbers::IMMUTABLE, $x) on line 78 can also be of type array or object<Samsara\Fermat\Ty...se\CoordinateInterface> or object<Samsara\Fermat\Ty...\Base\DecimalInterface> or object<Samsara\Fermat\Ty...Base\FractionInterface>; however, Samsara\Fermat\Provider\...ider::maclaurinSeries() does only seem to accept object<Samsara\Fermat\Types\Base\NumberInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
87
                function ($n) {
88
                    $negOne = Numbers::make(Numbers::IMMUTABLE, -1);
89
90
                    return $negOne->pow($n);
0 ignored issues
show
Bug introduced by
The method pow does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
                },
92
                function ($n) {
93
                    return SequenceProvider::nthOddNumber($n);
94
                },
95
                function ($n) {
96
                    $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n);
97
98
                    return $n->factorial()->multiply(SequenceProvider::nthOddNumber($n));
0 ignored issues
show
Bug introduced by
The method factorial does only exist in Samsara\Fermat\Types\Base\DecimalInterface, but not in Samsara\Fermat\Types\Bas...es\Base\NumberInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
99
                }
100
            )
101
        );
102
103
        return $answer;
104
105
    }
106
107
    /**
108
     * @param     $p
109
     * @param int $precision
110
     *
111
     * @return DecimalInterface|NumberInterface|ImmutableNumber
112
     * @throws IntegrityConstraint
113
     */
114
    public static function inverseNormalCDF($p, int $precision = 10)
115
    {
116
        $pi = Numbers::makePi();
117
        $r2pi = $pi->multiply(2)->sqrt();
0 ignored issues
show
Bug introduced by
The method sqrt does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
118
        $e = Numbers::makeE();
119
        $p = Numbers::makeOrDont(Numbers::IMMUTABLE, $p);
120
121
        $continue = true;
122
123
        $xCur = Numbers::make(Numbers::IMMUTABLE, $p);
124
125
        while ($continue) {
126
127
            $cumulative = self::normalCDF($xCur);
128
            $dx = $cumulative->subtract($p)->divide($r2pi->multiply($e->pow($xCur->pow(2))->divide(-2)));
0 ignored issues
show
Bug introduced by
The method divide does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
129
            $xCur = $xCur->subtract($dx);
130
131
            if ($dx->numberOfLeadingZeros() > $precision) {
132
                $continue = false;
133
            }
134
135
        }
136
137
        if ($p->isLessThan(0.5)) {
0 ignored issues
show
Bug introduced by
The method isLessThan does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
138
            return $xCur->multiply(-1);
139
        } else {
140
            return $xCur;
141
        }
142
    }
143
144
    /**
145
     * @param $n
146
     * @param $k
147
     *
148
     * @return DecimalInterface|NumberInterface|ImmutableNumber
149
     * @throws IntegrityConstraint
150
     * @throws IncompatibleObjectState
151
     */
152
    public static function binomialCoefficient($n, $k)
153
    {
154
155
        $n = Numbers::makeOrDont(Numbers::IMMUTABLE, $n);
156
        $k = Numbers::makeOrDont(Numbers::IMMUTABLE, $k);
157
158
        if ($k->isLessThan(0) || $n->isLessThan($k)) {
0 ignored issues
show
Bug introduced by
The method isLessThan does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
It seems like $k defined by \Samsara\Fermat\Numbers:...Numbers::IMMUTABLE, $k) on line 156 can also be of type array or object<Samsara\Fermat\Ty...se\CoordinateInterface> or object<Samsara\Fermat\Ty...\Base\DecimalInterface> or object<Samsara\Fermat\Ty...Base\FractionInterface>; however, Samsara\Fermat\Types\Bas...Interface::isLessThan() does only seem to accept integer|string|object<Sa...s\Base\NumberInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
159
            throw new IntegrityConstraint(
160
                '$k must be larger or equal to 0 and less than or equal to $n',
161
                'Provide valid $n and $k values such that 0 <= $k <= $n',
162
                'For $n choose $k, the values of $n and $k must satisfy the inequality 0 <= $k <= $n'
163
            );
164
        }
165
166
        if (!$n->isInt() || !$k->isInt()) {
0 ignored issues
show
Bug introduced by
The method isInt does only exist in Samsara\Fermat\Types\Base\DecimalInterface, but not in Samsara\Fermat\Types\Bas...es\Base\NumberInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
167
            throw new IntegrityConstraint(
168
                '$k and $n must be whole numbers',
169
                'Provide whole numbers for $n and $k',
170
                'For $n choose $k, the values $n and $k must be whole numbers'
171
            );
172
        }
173
174
        return $n->factorial()->divide($k->factorial()->multiply($n->subtract($k)->factorial()));
0 ignored issues
show
Bug introduced by
The method factorial does only exist in Samsara\Fermat\Types\Base\DecimalInterface, but not in Samsara\Fermat\Types\Bas...es\Base\NumberInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method subtract does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
175
176
    }
177
178
    /**
179
     * @param     $z
180
     * @param int $precision
181
     *
182
     * @return DecimalInterface|NumberInterface|ImmutableNumber
183
     * @throws IntegrityConstraint
184
     */
185
    public static function gammaFunction($z, int $precision = 10)
186
    {
187
        $z = Numbers::makeOrDont(Numbers::IMMUTABLE, $z);
188
189
        if ($z->isInt()) {
0 ignored issues
show
Bug introduced by
The method isInt does only exist in Samsara\Fermat\Types\Base\DecimalInterface, but not in Samsara\Fermat\Types\Bas...es\Base\NumberInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
190
            if ($z->isNegative() || $z->isEqual(0)) {
0 ignored issues
show
Bug introduced by
The method isNegative does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method isEqual does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
191
                throw new IntegrityConstraint(
192
                    'Non-positive integers are not valid gamma function arguments',
193
                    'Do not provide non-positive integers to this function',
194
                    'The gamma function is not defined for zero or negative integers, but is continuous for all other values'
195
                );
196
            }
197
            return $z->subtract(1)->factorial();
0 ignored issues
show
Bug introduced by
The method subtract does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Bas...\Base\FractionInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
198
        }
199
200
        $x = Numbers::makeZero();
201
        $e = Numbers::makeE();
202
        $gamma = Numbers::makeZero();
203
204
        $continue = true;
205
206
        while ($continue) {
207
208
            $adjustment = $x->pow(
0 ignored issues
show
Bug introduced by
The method multiply does only exist in Samsara\Fermat\Types\Base\NumberInterface, but not in Samsara\Fermat\Types\Base\DecimalInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
209
                $z->subtract(1)
210
            )->multiply(
211
                $e->pow(
212
                    $x->multiply(-1)
213
                )
214
            );
215
216
            $gamma = $gamma->add($adjustment);
217
218
            if ($adjustment->numberOfLeadingZeros() > $precision) {
219
                $continue = false;
220
            }
221
222
        }
223
224
        return $gamma;
225
    }
226
227
}