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 |
||
49 | View Code Duplication | class Rand extends \RandomLib\AbstractSource |
|
|
|||
50 | { |
||
51 | |||
52 | /** |
||
53 | * Return an instance of Strength indicating the strength of the source |
||
54 | * |
||
55 | * @return \SecurityLib\Strength An instance of one of the strength classes |
||
56 | */ |
||
57 | public static function getStrength() |
||
66 | |||
67 | /** |
||
68 | * Generate a random string of the specified size |
||
69 | * |
||
70 | * @param int $size The size of the requested random string |
||
71 | * |
||
72 | * @return string A string of the requested size |
||
73 | */ |
||
74 | public function generate($size) |
||
83 | } |
||
84 |
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.