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 |
||
| 8 | class ColorObject extends BlobObject |
||
|
|
|||
| 9 | { |
||
| 10 | public static $color_map = array( |
||
| 11 | 'aliceblue' => 'f0f8ff', |
||
| 12 | 'antiquewhite' => 'faebd7', |
||
| 13 | 'aqua' => '00ffff', |
||
| 14 | 'aquamarine' => '7fffd4', |
||
| 15 | 'azure' => 'f0ffff', |
||
| 16 | 'beige' => 'f5f5dc', |
||
| 17 | 'bisque' => 'ffe4c4', |
||
| 18 | 'black' => '000000', |
||
| 19 | 'blanchedalmond' => 'ffebcd', |
||
| 20 | 'blue' => '0000ff', |
||
| 21 | 'blueviolet' => '8a2be2', |
||
| 22 | 'brown' => 'a52a2a', |
||
| 23 | 'burlywood' => 'deb887', |
||
| 24 | 'cadetblue' => '5f9ea0', |
||
| 25 | 'chartreuse' => '7fff00', |
||
| 26 | 'chocolate' => 'd2691e', |
||
| 27 | 'coral' => 'ff7f50', |
||
| 28 | 'cornflowerblue' => '6495ed', |
||
| 29 | 'cornsilk' => 'fff8dc', |
||
| 30 | 'crimson' => 'dc143c', |
||
| 31 | 'cyan' => '00ffff', |
||
| 32 | 'darkblue' => '00008b', |
||
| 33 | 'darkcyan' => '008b8b', |
||
| 34 | 'darkgoldenrod' => 'b8860b', |
||
| 35 | 'darkgray' => 'a9a9a9', |
||
| 36 | 'darkgreen' => '006400', |
||
| 37 | 'darkgrey' => 'a9a9a9', |
||
| 38 | 'darkkhaki' => 'bdb76b', |
||
| 39 | 'darkmagenta' => '8b008b', |
||
| 40 | 'darkolivegreen' => '556b2f', |
||
| 41 | 'darkorange' => 'ff8c00', |
||
| 42 | 'darkorchid' => '9932cc', |
||
| 43 | 'darkred' => '8b0000', |
||
| 44 | 'darksalmon' => 'e9967a', |
||
| 45 | 'darkseagreen' => '8fbc8f', |
||
| 46 | 'darkslateblue' => '483d8b', |
||
| 47 | 'darkslategray' => '2f4f4f', |
||
| 48 | 'darkslategrey' => '2f4f4f', |
||
| 49 | 'darkturquoise' => '00ced1', |
||
| 50 | 'darkviolet' => '9400d3', |
||
| 51 | 'deeppink' => 'ff1493', |
||
| 52 | 'deepskyblue' => '00bfff', |
||
| 53 | 'dimgray' => '696969', |
||
| 54 | 'dimgrey' => '696969', |
||
| 55 | 'dodgerblue' => '1e90ff', |
||
| 56 | 'firebrick' => 'b22222', |
||
| 57 | 'floralwhite' => 'fffaf0', |
||
| 58 | 'forestgreen' => '228b22', |
||
| 59 | 'fuchsia' => 'ff00ff', |
||
| 60 | 'gainsboro' => 'dcdcdc', |
||
| 61 | 'ghostwhite' => 'f8f8ff', |
||
| 62 | 'gold' => 'ffd700', |
||
| 63 | 'goldenrod' => 'daa520', |
||
| 64 | 'gray' => '808080', |
||
| 65 | 'green' => '008000', |
||
| 66 | 'greenyellow' => 'adff2f', |
||
| 67 | 'grey' => '808080', |
||
| 68 | 'honeydew' => 'f0fff0', |
||
| 69 | 'hotpink' => 'ff69b4', |
||
| 70 | 'indianred' => 'cd5c5c', |
||
| 71 | 'indigo' => '4b0082', |
||
| 72 | 'ivory' => 'fffff0', |
||
| 73 | 'khaki' => 'f0e68c', |
||
| 74 | 'lavender' => 'e6e6fa', |
||
| 75 | 'lavenderblush' => 'fff0f5', |
||
| 76 | 'lawngreen' => '7cfc00', |
||
| 77 | 'lemonchiffon' => 'fffacd', |
||
| 78 | 'lightblue' => 'add8e6', |
||
| 79 | 'lightcoral' => 'f08080', |
||
| 80 | 'lightcyan' => 'e0ffff', |
||
| 81 | 'lightgoldenrodyellow' => 'fafad2', |
||
| 82 | 'lightgray' => 'd3d3d3', |
||
| 83 | 'lightgreen' => '90ee90', |
||
| 84 | 'lightgrey' => 'd3d3d3', |
||
| 85 | 'lightpink' => 'ffb6c1', |
||
| 86 | 'lightsalmon' => 'ffa07a', |
||
| 87 | 'lightseagreen' => '20b2aa', |
||
| 88 | 'lightskyblue' => '87cefa', |
||
| 89 | 'lightslategray' => '778899', |
||
| 90 | 'lightslategrey' => '778899', |
||
| 91 | 'lightsteelblue' => 'b0c4de', |
||
| 92 | 'lightyellow' => 'ffffe0', |
||
| 93 | 'lime' => '00ff00', |
||
| 94 | 'limegreen' => '32cd32', |
||
| 95 | 'linen' => 'faf0e6', |
||
| 96 | 'magenta' => 'ff00ff', |
||
| 97 | 'maroon' => '800000', |
||
| 98 | 'mediumaquamarine' => '66cdaa', |
||
| 99 | 'mediumblue' => '0000cd', |
||
| 100 | 'mediumorchid' => 'ba55d3', |
||
| 101 | 'mediumpurple' => '9370db', |
||
| 102 | 'mediumseagreen' => '3cb371', |
||
| 103 | 'mediumslateblue' => '7b68ee', |
||
| 104 | 'mediumspringgreen' => '00fa9a', |
||
| 105 | 'mediumturquoise' => '48d1cc', |
||
| 106 | 'mediumvioletred' => 'c71585', |
||
| 107 | 'midnightblue' => '191970', |
||
| 108 | 'mintcream' => 'f5fffa', |
||
| 109 | 'mistyrose' => 'ffe4e1', |
||
| 110 | 'moccasin' => 'ffe4b5', |
||
| 111 | 'navajowhite' => 'ffdead', |
||
| 112 | 'navy' => '000080', |
||
| 113 | 'oldlace' => 'fdf5e6', |
||
| 114 | 'olive' => '808000', |
||
| 115 | 'olivedrab' => '6b8e23', |
||
| 116 | 'orange' => 'ffa500', |
||
| 117 | 'orangered' => 'ff4500', |
||
| 118 | 'orchid' => 'da70d6', |
||
| 119 | 'palegoldenrod' => 'eee8aa', |
||
| 120 | 'palegreen' => '98fb98', |
||
| 121 | 'paleturquoise' => 'afeeee', |
||
| 122 | 'palevioletred' => 'db7093', |
||
| 123 | 'papayawhip' => 'ffefd5', |
||
| 124 | 'peachpuff' => 'ffdab9', |
||
| 125 | 'peru' => 'cd853f', |
||
| 126 | 'pink' => 'ffc0cb', |
||
| 127 | 'plum' => 'dda0dd', |
||
| 128 | 'powderblue' => 'b0e0e6', |
||
| 129 | 'purple' => '800080', |
||
| 130 | 'rebeccapurple' => '663399', |
||
| 131 | 'red' => 'ff0000', |
||
| 132 | 'rosybrown' => 'bc8f8f', |
||
| 133 | 'royalblue' => '4169e1', |
||
| 134 | 'saddlebrown' => '8b4513', |
||
| 135 | 'salmon' => 'fa8072', |
||
| 136 | 'sandybrown' => 'f4a460', |
||
| 137 | 'seagreen' => '2e8b57', |
||
| 138 | 'seashell' => 'fff5ee', |
||
| 139 | 'sienna' => 'a0522d', |
||
| 140 | 'silver' => 'c0c0c0', |
||
| 141 | 'skyblue' => '87ceeb', |
||
| 142 | 'slateblue' => '6a5acd', |
||
| 143 | 'slategray' => '708090', |
||
| 144 | 'slategrey' => '708090', |
||
| 145 | 'snow' => 'fffafa', |
||
| 146 | 'springgreen' => '00ff7f', |
||
| 147 | 'steelblue' => '4682b4', |
||
| 148 | 'tan' => 'd2b48c', |
||
| 149 | 'teal' => '008080', |
||
| 150 | 'thistle' => 'd8bfd8', |
||
| 151 | 'tomato' => 'ff6347', |
||
| 152 | 'turquoise' => '40e0d0', |
||
| 153 | 'violet' => 'ee82ee', |
||
| 154 | 'wheat' => 'f5deb3', |
||
| 155 | 'white' => 'ffffff', |
||
| 156 | 'whitesmoke' => 'f5f5f5', |
||
| 157 | 'yellow' => 'ffff00', |
||
| 158 | 'yellowgreen' => '9acd32', |
||
| 159 | ); |
||
| 160 | |||
| 161 | public $hints = array('color'); |
||
| 162 | public $color = null; |
||
| 163 | |||
| 164 | public function __construct($color) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Turns HSL color to RGB. Black magic. |
||
| 173 | * |
||
| 174 | * @param float $h Hue |
||
| 175 | * @param float $s Saturation |
||
| 176 | * @param float $l Lightness |
||
| 177 | * |
||
| 178 | * @return array RGB array |
||
| 179 | */ |
||
| 180 | public static function hslToRgb($h, $s, $l) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Helper function for hslToRgb. Even blacker magic. |
||
| 210 | * |
||
| 211 | * @return float Color value |
||
| 212 | */ |
||
| 213 | private static function hueToRgb($m1, $m2, $hue) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Converts RGB to HSL. Color inversion of previous black magic is white magic? |
||
| 231 | * |
||
| 232 | * @param float $red Red |
||
| 233 | * @param float $green Green |
||
| 234 | * @param float $blue Blue |
||
| 235 | * |
||
| 236 | * @return array HSL array |
||
| 237 | */ |
||
| 238 | public static function rgbToHsl($red, $green, $blue) |
||
| 284 | } |
||
| 285 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.