GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TextProtocolValues::decode()   B
last analyzed

Complexity

Conditions 11
Paths 8

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 19
c 1
b 0
f 0
nc 8
nop 2
dl 0
loc 27
ccs 19
cts 19
cp 1
crap 11
rs 7.3166

How to fix   Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Plasma Driver MySQL component
4
 * Copyright 2018-2019 PlasmaPHP, All Rights Reserved
5
 *
6
 * Website: https://github.com/PlasmaPHP
7
 * License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE
8
*/
9
10
namespace Plasma\Drivers\MySQL;
11
12
/**
13
 * Text protocol rowset values decoder.
14
 * @internal
15
 */
16
class TextProtocolValues {
17
    /**
18
     * Standard decode value, if type extensions failed.
19
     * @param \Plasma\ColumnDefinitionInterface  $column
20
     * @param string|null                        $param
21
     * @return mixed
22
     * @throws \Plasma\Exception
23
     */
24 10
    static function decode(\Plasma\ColumnDefinitionInterface $column, $param) {
25 10
        $type = $column->getType();
26 10
        $flags = $column->getFlags();
27
        
28 10
        if($param !== null && ($flags & \Plasma\Drivers\MySQL\FieldFlags::ZEROFILL_FLAG) === 0) {
29
            switch(true) {
30 10
                case ($type === 'LONG'):
31 1
                    if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) === 0 || \PHP_INT_SIZE > 4) {
32 1
                        $param = (int) $param;
33
                    }
34 1
                break;
35 10
                case ($type === 'LONGLONG'):
36 2
                    if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) === 0 && \PHP_INT_SIZE > 4) {
37 2
                        $param = (int) $param;
38
                    }
39 2
                break;
40 9
                case static::isTypeTinyShortInt($type):
41 1
                    $param = (int) $param;
42 1
                break;
43 8
                case static::isTypeFloat($type):
44 1
                    $param = (float) $param;
45 1
                break;
46
                // Other types are taken as string
47
            }
48
        }
49
        
50 10
        return $param;
51
    }
52
    
53
    /**
54
     * @param string  $type
55
     * @return bool
56
     */
57 9
    static function isTypeTinyShortInt(string $type): bool {
58 9
        $types = array('TINY', 'SHORT', 'INT24');
59 9
        return \in_array($type, $types, true);
60
    }
61
    
62
    /**
63
     * @param string  $type
64
     * @return bool
65
     */
66 8
    static function isTypeFloat(string $type): bool {
67 8
        $types = array('FLOAT', 'DOUBLE');
68 8
        return \in_array($type, $types, true);
69
    }
70
}
71