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 |
||
7 | class generate { |
||
8 | |||
9 | 1 | View Code Duplication | public static function rgb_contrast(int $r = 0, int $g = 0, int $b = 0) :array { |
16 | |||
17 | 1 | public static function rgb_invert(int $r = 0, int $g = 0, int $b = 0) :array { |
|
24 | |||
25 | 2 | public static function yiq_score(int $r = 0, int $g = 0, int $b = 0) :float { |
|
28 | |||
29 | 1 | public static function rand(int $min_r = 0, int $max_r = 255, int $min_g = 0, int $max_g = 255, int $min_b = 0, int $max_b = 255) :array { |
|
36 | |||
37 | public static function blend(float $r1, float $g1, float $b1, float $a1, float $r2, float $g2, float $b2, float $a2, float $amount = 50.0) :array { |
||
47 | } |
||
48 |
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.