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 DebtAmortizatorFactory extends CalculatorFactoryAbstract |
|
|
|||
14 | { |
||
15 | const MANUFACTURED_CLASS_NAME = 'FinanCalc\\Calculators\\DebtAmortizator'; |
||
16 | |||
17 | /** |
||
18 | * @param $debtPrincipal |
||
19 | * @param $debtNoOfPeriods |
||
20 | * @param $debtInterest |
||
21 | * @return DebtAmortizator |
||
22 | */ |
||
23 | public function newYearlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest) |
||
34 | |||
35 | /** |
||
36 | * @param $debtPrincipal |
||
37 | * @param $debtNoOfPeriods |
||
38 | * @param $debtInterest |
||
39 | * @return DebtAmortizator |
||
40 | */ |
||
41 | public function newMonthlyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest) |
||
52 | |||
53 | /** |
||
54 | * @param $debtPrincipal |
||
55 | * @param $debtNoOfPeriods |
||
56 | * @param $debtInterest |
||
57 | * @return DebtAmortizator |
||
58 | */ |
||
59 | public function newDailyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest) |
||
70 | |||
71 | /** |
||
72 | * @param $debtPrincipal |
||
73 | * @param $debtNoOfPeriods |
||
74 | * @param $debtInterest |
||
75 | * @param TimeSpan $debtPeriodLength |
||
76 | * @return \FinanCalc\Interfaces\Calculator\CalculatorAbstract |
||
77 | */ |
||
78 | public function newDebtAmortizationCustomPeriodLength( |
||
93 | } |
||
94 | } |
||
95 |
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.