AnnuityCalculatorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 93.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 70
loc 75
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A newYearlyAnnuity() 11 11 1
A newMonthlyAnnuity() 11 11 1
A newDailyAnnuity() 11 11 1
A newPerpetuity() 7 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace FinanCalc\Calculators\Factories {
4
5
    use FinanCalc\Calculators\AnnuityCalculator;
6
    use FinanCalc\Interfaces\Calculator\CalculatorFactoryAbstract;
7
    use FinanCalc\Utils\Time\TimeSpan;
8
9
    /**
10
     * Class AnnuityCalculatorFactory
11
     * @package FinanCalc\Calculators\Factories
12
     */
13 View Code Duplication
    class AnnuityCalculatorFactory extends CalculatorFactoryAbstract
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        const MANUFACTURED_CLASS_NAME = 'FinanCalc\\Calculators\\AnnuityCalculator';
16
17
        /**
18
         * @param $annuitySinglePaymentAmount
19
         * @param $annuityNoOfCompoundingPeriods
20
         * @param $annuityInterest
21
         * @return AnnuityCalculator
22
         */
23
        public function newYearlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest)
24
        {
25
            return $this->manufactureInstance(
26
                [
27
                    $annuitySinglePaymentAmount,
28
                    $annuityNoOfCompoundingPeriods,
29
                    TimeSpan::asDuration(1),
30
                    $annuityInterest
31
                ]
32
            );
33
        }
34
35
        /**
36
         * @param $annuitySinglePaymentAmount
37
         * @param $annuityNoOfCompoundingPeriods
38
         * @param $annuityInterest
39
         * @return AnnuityCalculator
40
         */
41
        public function newMonthlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest)
42
        {
43
            return $this->manufactureInstance(
44
                [
45
                    $annuitySinglePaymentAmount,
46
                    $annuityNoOfCompoundingPeriods,
47
                    TimeSpan::asDuration(0, 1),
48
                    $annuityInterest
49
                ]
50
            );
51
        }
52
53
        /**
54
         * @param $annuitySinglePaymentAmount
55
         * @param $annuityNoOfCompoundingPeriods
56
         * @param $annuityInterest
57
         * @return AnnuityCalculator
58
         */
59
        public function newDailyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest)
60
        {
61
            return $this->manufactureInstance(
62
                [
63
                    $annuitySinglePaymentAmount,
64
                    $annuityNoOfCompoundingPeriods,
65
                    TimeSpan::asDuration(0, 0, 1),
66
                    $annuityInterest
67
                ]
68
            );
69
        }
70
71
        /**
72
         * @param $annuitySinglePaymentAmount
73
         * @param $annuityInterest
74
         * @return AnnuityCalculator
75
         */
76
        public function newPerpetuity($annuitySinglePaymentAmount, $annuityInterest)
77
        {
78
            return $this->manufactureInstance(
79
                [
80
                    $annuitySinglePaymentAmount,
81
                    0,
82
                    TimeSpan::asDuration(0),
83
                    $annuityInterest
84
                ]
85
            );
86
        }
87
    }
88
}
89