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 |
||
15 | trait meta { |
||
16 | |||
17 | // protected static $valid_keys = array(); |
||
|
|||
18 | // protected static $default_value; |
||
19 | |||
20 | protected static function error($message) { |
||
23 | |||
24 | protected static function _validate_array_input($input) { |
||
48 | |||
49 | public static function _validate_hex_input($input) { |
||
61 | |||
62 | protected static function _validate_hex_input_str(string $input) :string { |
||
73 | |||
74 | protected static function _expand_hex_str(string $input) : string { |
||
80 | |||
81 | /** |
||
82 | * Color delta algorithm |
||
83 | * |
||
84 | * @param float $rgb The R, G, or B value |
||
85 | * @param float $max The max RGB value |
||
86 | * @param float $delta The delta value ($max - $min) |
||
87 | * @return float The color delta |
||
88 | */ |
||
89 | protected static function _rgbhsl_delta_rgb(float $rgb, float $max, float $delta) { |
||
92 | |||
93 | /** |
||
94 | * Calculate the hue as a percentage from RGB |
||
95 | * |
||
96 | * @param float &$h The variable to modify as hue |
||
97 | * @param float $r The red value as a percentage |
||
98 | * @param float $g The green value as a percentage |
||
99 | * @param float $b The blue value as a percentage |
||
100 | * @param float $max The max RGB value |
||
101 | * @param float $delta The delta value ($max - $min) |
||
102 | * @return void |
||
103 | */ |
||
104 | View Code Duplication | protected static function _rgbhsl_hue(float &$h, float $r, float $g, float $b, float $max, float $delta) { |
|
119 | |||
120 | /** |
||
121 | * Handle low hue values |
||
122 | * |
||
123 | * @param float &$r The red value to modify |
||
124 | * @param float &$g The green value to modify |
||
125 | * @param float &$b The blue value to modify |
||
126 | * @param float $c Potential R, G, or B value |
||
127 | * @param float $x Potential R, G, or B value |
||
128 | * @param float $h The hue |
||
129 | * @return void |
||
130 | */ |
||
131 | View Code Duplication | protected static function _hslrgb_low(float &$r, float &$g, float &$b, float $c, float $x, float $h) { |
|
146 | |||
147 | /** |
||
148 | * Handle high hue values |
||
149 | * |
||
150 | * @param float &$r The red value to modify |
||
151 | * @param float &$g The green value to modify |
||
152 | * @param float &$b The blue value to modify |
||
153 | * @param float $c Potential R, G, or B value |
||
154 | * @param float $x Potential R, G, or B value |
||
155 | * @param float $h The hue |
||
156 | * @return void |
||
157 | */ |
||
158 | View Code Duplication | protected static function _hslrgb_high(float &$r, float &$g, float &$b, float $c, float $x, float $h) { |
|
169 | } |
||
170 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.