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