Code Duplication    Length = 19-24 lines in 3 locations

src/Samsara/Fermat/Provider/Distribution/Exponential.php 2 locations

@@ 49-72 (lines=24) @@
46
     * @return ImmutableNumber
47
     * @throws IntegrityConstraint
48
     */
49
    public function cdf($x): ImmutableNumber
50
    {
51
52
        $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x);
53
        /** @var ImmutableNumber $one */
54
        $one = Numbers::makeOne();
55
56
        if (!$x->isPositive()) {
57
            throw new IntegrityConstraint(
58
                'X must be positive',
59
                'Provide a positive x',
60
                'Exponential distributions work on time to occurrence; the time to occurrence (x) must be positive'
61
            );
62
        }
63
64
        /** @var ImmutableNumber $e */
65
        $e = Numbers::makeE();
66
67
        /** @var ImmutableNumber $cdf */
68
        $cdf = $one->subtract($e->pow($x->multiply($this->lambda)->multiply(-1)));
69
70
        return $cdf;
71
72
    }
73
74
    /**
75
     * @param $x
@@ 80-101 (lines=22) @@
77
     * @return ImmutableNumber
78
     * @throws IntegrityConstraint
79
     */
80
    public function pdf($x): ImmutableNumber
81
    {
82
83
        $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x);
84
85
        if (!$x->isPositive()) {
86
            throw new IntegrityConstraint(
87
                'X must be positive',
88
                'Provide a positive x',
89
                'Exponential distributions work on time to occurrence; the time to occurrence (x) must be positive'
90
            );
91
        }
92
93
        /** @var ImmutableNumber $e */
94
        $e = Numbers::makeE();
95
96
        /** @var ImmutableNumber $pdf */
97
        $pdf = $this->lambda->multiply($e->pow($this->lambda->multiply(-1)->multiply($x)));
98
99
        return $pdf;
100
101
    }
102
103
    /**
104
     * @param $x1

src/Samsara/Fermat/Provider/Distribution/Poisson.php 1 location

@@ 96-114 (lines=19) @@
93
     * @throws IntegrityConstraint
94
     * @throws IncompatibleObjectState
95
     */
96
    public function pmf($x): ImmutableNumber
97
    {
98
        $x = Numbers::makeOrDont(Numbers::IMMUTABLE, $x);
99
100
        if (!$x->isNatural()) {
101
            throw new IntegrityConstraint(
102
                'Only integers are valid x values for Poisson distributions',
103
                'Provide an integer value to calculate the PMF',
104
                'Poisson distributions describe discrete occurrences; only integers are valid x values'
105
            );
106
        }
107
108
        $e = Numbers::makeE();
109
110
        /** @var ImmutableNumber $pmf */
111
        $pmf = $this->lambda->pow($x)->multiply($e->pow($this->lambda->multiply(-1)))->divide($x->factorial());
112
113
        return $pmf;
114
    }
115
116
    /**
117
     * @param int|float|DecimalInterface $x1