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 | class Helpers |
||
14 | { |
||
15 | /** |
||
16 | * Method to calculate how many dusts are necessary to max a pokemon |
||
17 | * @param float $pokemon the level of the pokemon |
||
18 | * @param float $trainer the level of the the trainer |
||
19 | * @return int dusts to max the pokemon |
||
20 | */ |
||
21 | View Code Duplication | public static function dustsToMax(float $pokemon, float $trainer) |
|
44 | |||
45 | /** |
||
46 | * Method to calculate how many candies are necessary to max a pokemon |
||
47 | * @param float $pokemon the level of the pokemon |
||
48 | * @param float $trainer the level of the the trainer |
||
49 | * @return int dusts to max the pokemon |
||
50 | */ |
||
51 | View Code Duplication | public static function candiesToMax(float $pokemon, float $trainer) |
|
74 | } |
||
75 |
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.