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 |
||
13 | View Code Duplication | class BondFairValueCalculatorFactory extends CalculatorFactoryAbstract |
|
|
|||
14 | { |
||
15 | const MANUFACTURED_CLASS_NAME = 'FinanCalc\\Calculators\\BondFairValueCalculator'; |
||
16 | |||
17 | /** |
||
18 | * @param $bondFaceValue |
||
19 | * @param $bondAnnualCouponRate |
||
20 | * @param $bondVIR |
||
21 | * @param $bondYearsToMaturity |
||
22 | * @return BondFairValueCalculator |
||
23 | */ |
||
24 | public function newAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) |
||
35 | |||
36 | /** |
||
37 | * @param $bondFaceValue |
||
38 | * @param $bondAnnualCouponRate |
||
39 | * @param $bondVIR |
||
40 | * @param $bondYearsToMaturity |
||
41 | * @return BondFairValueCalculator |
||
42 | */ |
||
43 | public function newSemiAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) |
||
55 | |||
56 | /** |
||
57 | * @param $bondFaceValue |
||
58 | * @param $bondAnnualCouponRate |
||
59 | * @param $bondVIR |
||
60 | * @param $bondYearsToMaturity |
||
61 | * @return BondFairValueCalculator |
||
62 | */ |
||
63 | public function newQuarterlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) |
||
75 | |||
76 | /** |
||
77 | * @param $bondFaceValue |
||
78 | * @param $bondAnnualCouponRate |
||
79 | * @param $bondVIR |
||
80 | * @param $bondYearsToMaturity |
||
81 | * @return BondFairValueCalculator |
||
82 | */ |
||
83 | public function newMonthlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) |
||
95 | |||
96 | /** |
||
97 | * @param $bondFaceValue |
||
98 | * @param $bondAnnualCouponRate |
||
99 | * @param $bondVIR |
||
100 | * @param $bondYearsToMaturity |
||
101 | * @param $bondPaymentFrequency |
||
102 | * @return BondFairValueCalculator |
||
103 | */ |
||
104 | public function newCustomCouponFrequencyBond( |
||
121 | } |
||
122 | } |
||
123 |
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.