| Conditions | 1 |
| Paths | 1 |
| Total Lines | 261 |
| Code Lines | 226 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 10 | public function colorProvider() |
||
| 11 | { |
||
| 12 | return array( |
||
| 13 | 'name 1' => array( |
||
| 14 | 'red', |
||
| 15 | 0xFF, |
||
| 16 | 0, |
||
| 17 | 0, |
||
| 18 | 1.0, |
||
| 19 | ColorRepresentation::COLOR_NAME, |
||
| 20 | ), |
||
| 21 | 'name 2' => array( |
||
| 22 | 'fuchsia', |
||
| 23 | 0xFF, |
||
| 24 | 0, |
||
| 25 | 0xFF, |
||
| 26 | 1.0, |
||
| 27 | ColorRepresentation::COLOR_NAME, |
||
| 28 | ), |
||
| 29 | 'name 3' => array( |
||
| 30 | 'BLUE', |
||
| 31 | 0, |
||
| 32 | 0, |
||
| 33 | 0xFF, |
||
| 34 | 1.0, |
||
| 35 | ColorRepresentation::COLOR_NAME, |
||
| 36 | ), |
||
| 37 | 'name 4' => array( |
||
| 38 | ' white ', |
||
| 39 | 0xFF, |
||
| 40 | 0xFF, |
||
| 41 | 0xFF, |
||
| 42 | 1.0, |
||
| 43 | ColorRepresentation::COLOR_NAME, |
||
| 44 | ), |
||
| 45 | 'name 5' => array( |
||
| 46 | 'transparent', |
||
| 47 | 0, |
||
| 48 | 0, |
||
| 49 | 0, |
||
| 50 | 0.0, |
||
| 51 | ColorRepresentation::COLOR_NAME, |
||
| 52 | ), |
||
| 53 | 'hex-3' => array( |
||
| 54 | '#FED', |
||
| 55 | 0xFF, |
||
| 56 | 0xEE, |
||
| 57 | 0xDD, |
||
| 58 | 1.0, |
||
| 59 | ColorRepresentation::COLOR_HEX_3, |
||
| 60 | ), |
||
| 61 | 'hex-6' => array( |
||
| 62 | '#F00BA8', |
||
| 63 | 0xF0, |
||
| 64 | 0x0B, |
||
| 65 | 0xA8, |
||
| 66 | 1.0, |
||
| 67 | ColorRepresentation::COLOR_HEX_6, |
||
| 68 | ), |
||
| 69 | 'rgb' => array( |
||
| 70 | 'rgb(123, 45, 67)', |
||
| 71 | 123, |
||
| 72 | 45, |
||
| 73 | 67, |
||
| 74 | 1.0, |
||
| 75 | ColorRepresentation::COLOR_RGB, |
||
| 76 | ), |
||
| 77 | 'rgb alpha' => array( |
||
| 78 | 'rgb(123, 45, 67, 0.5)', |
||
| 79 | 123, |
||
| 80 | 45, |
||
| 81 | 67, |
||
| 82 | 0.5, |
||
| 83 | ColorRepresentation::COLOR_RGB, |
||
| 84 | ), |
||
| 85 | 'rgb alpha percent' => array( |
||
| 86 | 'rgb(50%, 60%, 70%, 50%)', |
||
| 87 | 128, |
||
| 88 | 153, |
||
| 89 | 179, |
||
| 90 | 0.5, |
||
| 91 | ColorRepresentation::COLOR_RGB, |
||
| 92 | ), |
||
| 93 | 'rgb alpha whitespace' => array( |
||
| 94 | ' rgb ( 123 45 67 / 0.5 ) ', |
||
| 95 | 123, |
||
| 96 | 45, |
||
| 97 | 67, |
||
| 98 | 0.5, |
||
| 99 | ColorRepresentation::COLOR_RGB, |
||
| 100 | ), |
||
| 101 | 'rgb uppercase' => array( |
||
| 102 | 'RGB(1, 2, 3)', |
||
| 103 | 1, |
||
| 104 | 2, |
||
| 105 | 3, |
||
| 106 | 1.0, |
||
| 107 | ColorRepresentation::COLOR_RGB, |
||
| 108 | ), |
||
| 109 | 'rgba' => array( |
||
| 110 | 'rgba(123, 45, 67, 0.5)', |
||
| 111 | 123, |
||
| 112 | 45, |
||
| 113 | 67, |
||
| 114 | 0.5, |
||
| 115 | ColorRepresentation::COLOR_RGBA, |
||
| 116 | ), |
||
| 117 | 'rgba without alpha' => array( |
||
| 118 | 'rgba(123, 45, 67)', |
||
| 119 | 123, |
||
| 120 | 45, |
||
| 121 | 67, |
||
| 122 | 1.0, |
||
| 123 | ColorRepresentation::COLOR_RGBA, |
||
| 124 | ), |
||
| 125 | 'hsl' => array( |
||
| 126 | 'hsl(120, 100%, 50%)', |
||
| 127 | 0, |
||
| 128 | 0xFF, |
||
| 129 | 0, |
||
| 130 | 1.0, |
||
| 131 | ColorRepresentation::COLOR_HSL, |
||
| 132 | ), |
||
| 133 | 'hsl alpha' => array( |
||
| 134 | 'hsl(120, 100%, 50%, 0.35)', |
||
| 135 | 0, |
||
| 136 | 0xFF, |
||
| 137 | 0, |
||
| 138 | 0.35, |
||
| 139 | ColorRepresentation::COLOR_HSL, |
||
| 140 | ), |
||
| 141 | 'hsl alpha percent' => array( |
||
| 142 | 'hsl(120, 100%, 50%, 35%)', |
||
| 143 | 0, |
||
| 144 | 0xFF, |
||
| 145 | 0, |
||
| 146 | 0.35, |
||
| 147 | ColorRepresentation::COLOR_HSL, |
||
| 148 | ), |
||
| 149 | 'hsl alpha whitespace' => array( |
||
| 150 | ' hsl ( 120 100% 50% / 0.35 ) ', |
||
| 151 | 0, |
||
| 152 | 0xFF, |
||
| 153 | 0, |
||
| 154 | 0.35, |
||
| 155 | ColorRepresentation::COLOR_HSL, |
||
| 156 | ), |
||
| 157 | 'hsl hue overflow' => array( |
||
| 158 | 'hsl(480, 100%, 50%)', |
||
| 159 | 0, |
||
| 160 | 0xFF, |
||
| 161 | 0, |
||
| 162 | 1.0, |
||
| 163 | ColorRepresentation::COLOR_HSL, |
||
| 164 | ), |
||
| 165 | 'hsl hue underflow' => array( |
||
| 166 | 'hsl(-240, 100%, 50%)', |
||
| 167 | 0, |
||
| 168 | 0xFF, |
||
| 169 | 0, |
||
| 170 | 1.0, |
||
| 171 | ColorRepresentation::COLOR_HSL, |
||
| 172 | ), |
||
| 173 | 'hsla' => array( |
||
| 174 | 'hsla(120, 100%, 50%, 35%)', |
||
| 175 | 0, |
||
| 176 | 0xFF, |
||
| 177 | 0, |
||
| 178 | 0.35, |
||
| 179 | ColorRepresentation::COLOR_HSLA, |
||
| 180 | ), |
||
| 181 | 'hsla without alpha' => array( |
||
| 182 | 'hsla(120, 100%, 50%)', |
||
| 183 | 0, |
||
| 184 | 0xFF, |
||
| 185 | 0, |
||
| 186 | 1.0, |
||
| 187 | ColorRepresentation::COLOR_HSLA, |
||
| 188 | ), |
||
| 189 | 'hex-4' => array( |
||
| 190 | '#FA84', |
||
| 191 | 0xFF, |
||
| 192 | 0xAA, |
||
| 193 | 0x88, |
||
| 194 | 0x4 / 0xF, |
||
| 195 | ColorRepresentation::COLOR_HEX_4, |
||
| 196 | ), |
||
| 197 | 'hex-8' => array( |
||
| 198 | '#FEDCBA98', |
||
| 199 | 0xFE, |
||
| 200 | 0xDC, |
||
| 201 | 0xBA, |
||
| 202 | 0x98 / 0xFF, |
||
| 203 | ColorRepresentation::COLOR_HEX_8, |
||
| 204 | ), |
||
| 205 | 'invalid' => array( |
||
| 206 | "Wait a minute... This isn't a color!", |
||
| 207 | 0, |
||
| 208 | 0, |
||
| 209 | 0, |
||
| 210 | 1.0, |
||
| 211 | null, |
||
| 212 | ), |
||
| 213 | 'invalid hex' => array( |
||
| 214 | '#colorsarecool', |
||
| 215 | 0, |
||
| 216 | 0, |
||
| 217 | 0, |
||
| 218 | 1.0, |
||
| 219 | null, |
||
| 220 | ), |
||
| 221 | 'invalid func 1' => array( |
||
| 222 | 'rgb()', |
||
| 223 | 0, |
||
| 224 | 0, |
||
| 225 | 0, |
||
| 226 | 1.0, |
||
| 227 | null, |
||
| 228 | ), |
||
| 229 | 'invalid func 2' => array( |
||
| 230 | 'rgb(1, 2, 3, 4, 5)', |
||
| 231 | 0, |
||
| 232 | 0, |
||
| 233 | 0, |
||
| 234 | 1.0, |
||
| 235 | null, |
||
| 236 | ), |
||
| 237 | 'invalid range' => array( |
||
| 238 | 'rgb(300, 300, 300)', |
||
| 239 | 0, |
||
| 240 | 0, |
||
| 241 | 0, |
||
| 242 | 1.0, |
||
| 243 | null, |
||
| 244 | ), |
||
| 245 | 'invalid alpha range' => array( |
||
| 246 | 'rgb(0, 0, 0, 2)', |
||
| 247 | 0, |
||
| 248 | 0, |
||
| 249 | 0, |
||
| 250 | 1.0, |
||
| 251 | null, |
||
| 252 | ), |
||
| 253 | 'invalid hsl range' => array( |
||
| 254 | 'hsl(0, 120%, 120%)', |
||
| 255 | 0, |
||
| 256 | 0, |
||
| 257 | 0, |
||
| 258 | 1.0, |
||
| 259 | null, |
||
| 260 | ), |
||
| 261 | 'invalid hsl alpha range' => array( |
||
| 262 | 'hsl(0, 0%, 0%, 2)', |
||
| 263 | 0, |
||
| 264 | 0, |
||
| 265 | 0, |
||
| 266 | 1.0, |
||
| 267 | null, |
||
| 268 | ), |
||
| 269 | ); |
||
| 270 | } |
||
| 271 | |||
| 434 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.