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.
Passed
Push — master ( 6078a4...f68c38 )
by Charlotte
02:21
created

StatementExecuteCommand::stdDecodeBinaryValue()   C

Complexity

Conditions 16
Paths 15

Size

Total Lines 66
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 48
CRAP Score 16.052

Importance

Changes 0
Metric Value
cc 16
eloc 54
nc 15
nop 2
dl 0
loc 66
ccs 48
cts 51
cp 0.9412
crap 16.052
rs 5.5666
c 0
b 0
f 0

How to fix   Long Method    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 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\Commands;
11
12
/**
13
 * Statement Execute command.
14
 * @internal
15
 */
16
class StatementExecuteCommand extends QueryCommand {
17
    /**
18
     * The identifier for this command.
19
     * @var int
20
     * @source
21
     */
22
    const COMMAND_ID = 0x17;
23
    
24
    /**
25
     * @var mixed
26
     */
27
    protected $id;
28
    
29
    /**
30
     * @var array
31
     */
32
    protected $params;
33
    
34
    /**
35
     * Constructor.
36
     * @param \Plasma\DriverInterface  $driver
37
     * @param mixed                    $id
38
     * @param string                   $query
39
     * @param array                    $params
40
     */
41 37
    function __construct(\Plasma\DriverInterface $driver, $id, string $query, array $params) {
42 37
        parent::__construct($driver, $query);
43
        
44 37
        $this->id = $id;
45 37
        $this->params = $params;
46 37
    }
47
    
48
    /**
49
     * Get the encoded message for writing to the database connection.
50
     * @return string
51
     */
52 36
    function getEncodedMessage(): string {
53 36
        $packet = \chr(static::COMMAND_ID);
54 36
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->id);
55
        
56 36
        $packet .= "\x00"; // Cursor type flag
57 36
        $packet .= \Plasma\BinaryBuffer::writeInt4(1); // Iteration count is always 1
58
        
59 36
        $bitmapOffset = \strlen($packet);
60 36
        $packet .= \str_repeat("\x00", ((\count($this->params) + 7) >> 3));
61
        
62 36
        $bound = 0;
63
        
64 36
        $types = '';
65 36
        $values = '';
66
        
67 36
        foreach($this->params as $id => $param) {
68 36
            if($param === null) {
69 1
                $offset = $bitmapOffset + ($id >> 3);
70 1
                $packet[$offset] = $packet[$offset] | \chr((1 << ($id % 8)));
71
            } else {
72 36
                $bound = 1;
73
            }
74
            
75
            try {
76 36
                $manager = \Plasma\Types\TypeExtensionsManager::getManager('driver-mysql');
77
                $encode = $manager->encodeType($param);
78
                
79
                $unsigned = $encode->isUnsigned();
80
                $type = $encode->getSQLType();
81
                $value = $encode->getValue();
82
                
83
                [ ,, $value ] = \Plasma\Drivers\MySQL\BinaryProtocolValues::encode($value);
84 36
            } catch (\Plasma\Exception $e) {
85 36
                [ $unsigned, $type, $value ] = \Plasma\Drivers\MySQL\BinaryProtocolValues::encode($param);
86
            }
87
            
88 35
            $types .= \chr($type).($unsigned ? "\x80" : "\x00");
89 35
            $values .= $value;
90
        }
91
        
92 35
        $packet .= \chr($bound);
93
        
94 35
        if($bound) {
95 35
            $packet .= $types;
96 35
            $packet .= $values;
97
        }
98
        
99 35
        return $packet;
100
    }
101
    
102
    /**
103
     * Whether the sequence ID should be resetted.
104
     * @return bool
105
     */
106 36
    function resetSequence(): bool {
107 36
        return true;
108
    }
109
    
110
    /**
111
     * Parses the binary resultset row and returns the row.
112
     * @param \Plasma\BinaryBuffer  $buffer
113
     * @return array
114
     */
115 35
    protected function parseResultsetRow(\Plasma\BinaryBuffer $buffer): array {
116 35
        $buffer->read(1); // remove packet header
117
        
118 35
        $nullRow = array();
119 35
        $i = 0;
120
        
121
        /** @var \Plasma\ColumnDefinitionInterface  $column */
122 35
        foreach($this->fields as $column) { // Handle NULL-bitmap
123 35
            if((\ord($buffer[(($i + 2) >> 3)]) & (1 << (($i + 2) % 8))) !== 0) {
124 2
                $nullRow[$column->getName()] = null;
125
            }
126
            
127 35
            $i++;
128
        }
129
        
130 35
        $buffer->read(((\count($this->fields) + 9) >> 3)); // Remove NULL-bitmap
131 35
        $row = array();
132
        
133
        /** @var \Plasma\ColumnDefinitionInterface  $column */
134 35
        foreach($this->fields as $column) {
135 35
            if(\array_key_exists($column->getName(), $nullRow)) {
136 2
                $row[$column->getName()] = null;
137 2
                continue;
138
            }
139
            
140 35
            $value = \Plasma\Drivers\MySQL\BinaryProtocolValues::decode($column, $buffer);
141 35
            $parsedValue = $column->parseValue($value);
142
            
143 35
            if($value !== $parsedValue) {
144
                $value = $parsedValue;
145
            }
146
            
147 35
            $row[$column->getName()] = $value;
148
        }
149
        
150 35
        return $row;
151
    }
152
}
153