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.
Completed
Push — master ( 96398e...4babe8 )
by Charlotte
09:11
created

StatementExecuteCommand   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Test Coverage

Coverage 93.1%

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 141
ccs 54
cts 58
cp 0.931
rs 10
c 0
b 0
f 0
wmc 14

4 Methods

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