| Conditions | 26 |
| Paths | 27 |
| Total Lines | 123 |
| Code Lines | 94 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 80 |
| CRAP Score | 26.2298 |
| 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 |
||
| 208 | 35 | protected function stdDecodeBinaryValue(\Plasma\ColumnDefinitionInterface $column, \Plasma\BinaryBuffer $buffer) { |
|
| 209 | 35 | $flags = $column->getFlags(); |
|
| 210 | 35 | $type = $column->getType(); |
|
| 211 | |||
| 212 | switch(true) { |
||
| 213 | 35 | case $this->isTypeString($type): |
|
|
1 ignored issue
–
show
|
|||
| 214 | 18 | $value = $buffer->readStringLength(); |
|
| 215 | 18 | break; |
|
| 216 | 17 | case ($type === 'TINY'): |
|
| 217 | 7 | $value = $buffer->readInt1(); |
|
| 218 | 7 | $value = $this->zeroFillInts($column, $value); |
|
| 219 | 7 | break; |
|
|
1 ignored issue
–
show
|
|||
| 220 | 17 | case $this->isTypeShortOrYear($type): |
|
|
1 ignored issue
–
show
|
|||
| 221 | 7 | $value = $buffer->readInt2(); |
|
| 222 | 7 | $value = $this->zeroFillInts($column, $value); |
|
| 223 | 7 | break; |
|
|
1 ignored issue
–
show
|
|||
| 224 | 17 | case $this->isTypeInt24orLong($type): |
|
|
1 ignored issue
–
show
|
|||
| 225 | 7 | $value = $buffer->readInt4(); |
|
| 226 | |||
| 227 | 7 | if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) !== 0 && \PHP_INT_SIZE <= 4) { |
|
| 228 | $value = \bcadd($value, '18446744073709551616'); |
||
| 229 | } |
||
| 230 | |||
| 231 | 7 | $value = $this->zeroFillInts($column, $value); |
|
| 232 | 7 | break; |
|
| 233 | 17 | case ($type === 'LONGLONG'): |
|
| 234 | 7 | $value = $buffer->readInt8(); |
|
| 235 | |||
| 236 | 7 | if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) !== 0) { |
|
| 237 | $value = \bcadd($value, '18446744073709551616'); |
||
| 238 | 7 | } elseif(\PHP_INT_SIZE > 4) { |
|
| 239 | 7 | $value = (int) $value; |
|
| 240 | } |
||
| 241 | |||
| 242 | 7 | $value = $this->zeroFillInts($column, $value); |
|
| 243 | 7 | break; |
|
| 244 | 10 | case ($type === 'FLOAT'): |
|
| 245 | 2 | $value = $buffer->readFloat(); |
|
| 246 | 2 | break; |
|
| 247 | 10 | case ($type === 'DOUBLE'): |
|
| 248 | 2 | $value = $buffer->readDouble(); |
|
| 249 | 2 | break; |
|
| 250 | 8 | case $this->isTypeDate($type): |
|
|
1 ignored issue
–
show
|
|||
| 251 | 8 | $length = $buffer->readIntLength(); |
|
| 252 | 8 | if($length > 0) { |
|
| 253 | 1 | $year = $buffer->readInt2(); |
|
| 254 | 1 | $month = $buffer->readInt1(); |
|
| 255 | 1 | $day = $buffer->readInt1(); |
|
| 256 | |||
| 257 | 1 | $value = \sprintf('%04d-%02d-%02d', $year, $month, $day); |
|
| 258 | } else { |
||
| 259 | 7 | $value = '0000-00-00'; |
|
| 260 | } |
||
|
1 ignored issue
–
show
|
|||
| 261 | 8 | break; |
|
|
1 ignored issue
–
show
|
|||
| 262 | 8 | case $this->isTypeDateTime($type): |
|
|
1 ignored issue
–
show
|
|||
| 263 | 8 | $length = $buffer->readIntLength(); |
|
| 264 | 8 | if($length > 0) { |
|
| 265 | 2 | $year = $buffer->readInt2(); |
|
| 266 | 2 | $month = $buffer->readInt1(); |
|
| 267 | 2 | $day = $buffer->readInt1(); |
|
| 268 | |||
| 269 | 2 | if($length > 4) { |
|
| 270 | 1 | $hour = $buffer->readInt1(); |
|
| 271 | 1 | $min = $buffer->readInt1(); |
|
| 272 | 1 | $sec = $buffer->readInt1(); |
|
| 273 | } else { |
||
| 274 | 1 | $hour = 0; |
|
| 275 | 1 | $min = 0; |
|
| 276 | 1 | $sec = 0; |
|
| 277 | } |
||
| 278 | |||
| 279 | 2 | if($length > 7) { |
|
| 280 | $microI = $buffer->readInt4(); |
||
| 281 | } else { |
||
| 282 | 2 | $microI = 0; |
|
| 283 | } |
||
| 284 | |||
| 285 | 2 | $micro = \str_pad($microI, 6, '0', \STR_PAD_LEFT); |
|
| 286 | 2 | $micro = \substr($micro, 0, 3).' '.\substr($micro, 3); |
|
| 287 | |||
| 288 | 2 | $value = \sprintf('%04d-%02d-%02d %02d:%02d:%02d'.($microI > 0 ? '.%s' : ''), $year, $month, $day, $hour, $min, $sec, $micro); |
|
| 289 | |||
| 290 | 2 | if($type === 'TIMESTAMP') { |
|
| 291 | 2 | $value = \DateTime::createFromFormat('Y-m-d H:i:s'.($microI > 0 ? '.u' : ''), $value)->getTimestamp(); |
|
| 292 | } |
||
| 293 | } else { |
||
| 294 | 8 | $value = '0000-00-00 00:00:00.000 000'; |
|
| 295 | } |
||
| 296 | 8 | break; |
|
| 297 | 8 | case ($type === 'TIME'): |
|
| 298 | 8 | $length = $buffer->readIntLength(); |
|
| 299 | 8 | if($length > 1) { |
|
| 300 | 1 | $sign = $buffer->readInt1(); |
|
| 301 | 1 | $days = $buffer->readInt4(); |
|
| 302 | |||
| 303 | 1 | if($sign === 1) { |
|
| 304 | $days *= -1; |
||
| 305 | } |
||
| 306 | |||
| 307 | 1 | $hour = $buffer->readInt1(); |
|
| 308 | 1 | $min = $buffer->readInt1(); |
|
| 309 | 1 | $sec = $buffer->readInt1(); |
|
| 310 | |||
| 311 | 1 | if($length > 8) { |
|
| 312 | $microI = $buffer->readInt4(); |
||
| 313 | } else { |
||
| 314 | 1 | $microI = 0; |
|
| 315 | } |
||
| 316 | |||
| 317 | 1 | $micro = \str_pad($microI, 6, '0', \STR_PAD_LEFT); |
|
| 318 | 1 | $micro = \substr($micro, 0, 3).' '.\substr($micro, 3); |
|
| 319 | |||
| 320 | 1 | $value = \sprintf('%dd %02d:%02d:%02d'.($microI > 0 ? '.%s' : ''), $days, $hour, $min, $sec, $micro); |
|
| 321 | } else { |
||
| 322 | 7 | $value = '0d 00:00:00'; |
|
| 323 | } |
||
| 324 | 8 | break; |
|
| 325 | default: |
||
| 326 | throw new \InvalidArgumentException('Unknown column type (flags: '.$flags.', type: '.$column->getType().')'); |
||
| 327 | break; |
||
| 328 | } |
||
| 329 | |||
| 330 | 35 | return $value; |
|
| 331 | } |
||
| 398 |