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 |
||
| 29 | View Code Duplication | class LanguageBs extends Language { |
|
|
|
|||
| 30 | /** |
||
| 31 | * Convert from the nominative form of a noun to some other case |
||
| 32 | * Invoked with {{GRAMMAR:case|word}} |
||
| 33 | * |
||
| 34 | * Cases: genitiv, dativ, akuzativ, vokativ, instrumental, lokativ |
||
| 35 | * |
||
| 36 | * @param string $word |
||
| 37 | * @param string $case |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | function convertGrammar( $word, $case ) { |
||
| 59 | } |
||
| 60 |
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.