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 BondYTMCalculatorFactory extends CalculatorFactoryAbstract |
|
|
|||
14 | { |
||
15 | const MANUFACTURED_CLASS_NAME = 'FinanCalc\\Calculators\\BondYTMCalculator'; |
||
16 | |||
17 | /** |
||
18 | * @param $bondFaceValue |
||
19 | * @param $bondMarketValue |
||
20 | * @param $bondAnnualCouponRate |
||
21 | * @param $bondYearsToMaturity |
||
22 | * @return BondYTMCalculator |
||
23 | * @internal param $bondVIR |
||
24 | */ |
||
25 | public function newAnnualCouponsBond( |
||
40 | |||
41 | /** |
||
42 | * @param $bondFaceValue |
||
43 | * @param $bondMarketValue |
||
44 | * @param $bondAnnualCouponRate |
||
45 | * @param $bondYearsToMaturity |
||
46 | * @return BondYTMCalculator |
||
47 | * @internal param $bondVIR |
||
48 | */ |
||
49 | public function newSemiAnnualCouponsBond( |
||
65 | |||
66 | /** |
||
67 | * @param $bondFaceValue |
||
68 | * @param $bondMarketValue |
||
69 | * @param $bondAnnualCouponRate |
||
70 | * @param $bondYearsToMaturity |
||
71 | * @return BondYTMCalculator |
||
72 | * @internal param $bondVIR |
||
73 | */ |
||
74 | public function newQuarterlyCouponsBond( |
||
90 | |||
91 | /** |
||
92 | * @param $bondFaceValue |
||
93 | * @param $bondMarketValue |
||
94 | * @param $bondAnnualCouponRate |
||
95 | * @param $bondYearsToMaturity |
||
96 | * @return BondYTMCalculator |
||
97 | * @internal param $bondVIR |
||
98 | */ |
||
99 | public function newMonthlyCouponsBond( |
||
115 | |||
116 | /** |
||
117 | * @param $bondFaceValue |
||
118 | * @param $bondMarketValue |
||
119 | * @param $bondAnnualCouponRate |
||
120 | * @param $bondYearsToMaturity |
||
121 | * @param $bondPaymentFrequency |
||
122 | * @return BondYTMCalculator |
||
123 | * @internal param $bondVIR |
||
124 | */ |
||
125 | public function newCustomCouponFrequencyBond( |
||
142 | } |
||
143 | } |
||
144 |
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.