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.
Failed Conditions
Push — master ( 888a68...c84b74 )
by Charlotte
05:53
created

StatementExecuteCommand::parseResultsetRow()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 12
nop 1
dl 0
loc 34
ccs 0
cts 24
cp 0
crap 42
rs 9.0444
c 0
b 0
f 0
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
    function __construct(\Plasma\DriverInterface $driver, $id, string $query, array $params) {
42
        parent::__construct($driver, $query);
43
        
44
        $this->id = $id;
45
        $this->params = $params;
46
    }
47
    
48
    /**
49
     * Get the encoded message for writing to the database connection.
50
     * @return string
51
     */
52
    function getEncodedMessage(): string {
53
        $packet = \chr(static::COMMAND_ID);
54
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->id);
55
        
56
        $packet .= "\x00"; // Cursor type flag
57
        $packet .= \Plasma\BinaryBuffer::writeInt4(1); // Iteration count is always 1
58
        
59
        $bitmapOffset = \strlen($packet);
60
        $packet .= \str_repeat("\x00", ((\count($this->params) + 7) >> 3));
61
        
62
        $bound = 0;
63
        
64
        $types = '';
65
        $values = '';
66
        
67
        foreach($this->params as $id => $param) {
68
            if($param === null) {
69
                $offset = $bitmapOffset + ($id >> 3);
70
                $packet[$offset] = $packet[$offset] | \chr((1 << ($id % 8)));
71
            } else {
72
                $bound = 1;
73
            }
74
            
75
            try {
76
                $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
            } catch (\Plasma\Exception $e) {
83
                [ $unsigned, $type, $value ] = $this->stdEncodeValue($param);
84
            }
85
            
86
            $types .= \chr($type).($unsigned ? "\x80" : "\x00");
87
            $values .= $value;
88
            var_dump($param, unpack('C*', $value));
0 ignored issues
show
Security Debugging Code introduced by
var_dump($param, unpack('C*', $value)) looks like debug code. Are you sure you do not want to remove it?
Loading history...
89
        }
90
        
91
        $packet .= \chr($bound);
92
        
93
        if($bound) {
94
            $packet .= $types;
95
            $packet .= $values;
96
        }
97
        
98
        return $packet;
99
    }
100
    
101
    /**
102
     * Whether the sequence ID should be resetted.
103
     * @return bool
104
     */
105
    function resetSequence(): bool {
106
        return true;
107
    }
108
    
109
    /**
110
     * Parses the binary resultset row and returns the row.
111
     * @param \Plasma\ColumnDefinitionInterface  $column
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $column does not match actual variable name $buffer
Loading history...
112
     * @param \Plasma\BinaryBuffer               $buffer
0 ignored issues
show
Coding Style introduced by
Superfluous parameter comment
Loading history...
113
     * @return array
114
     */
115
    protected function parseResultsetRow(\Plasma\BinaryBuffer $buffer): array {
116
        $nullRow = array();
117
        $i = 0;
118
        
119
        /** @var \Plasma\ColumnDefinitionInterface  $column */
120
        foreach($this->fields as $column) { // Handle NULL-bitmap
121
            if((\ord($buffer[(($i + 2) >> 3)]) & (1 << (($i + 2) % 8))) !== 0) {
122
                $nullRow[$column->getName()] = null;
123
            }
124
            
125
            $i++;
126
        }
127
        
128
        $buffer->read(((\count($this->fields) + 9) >> 3)); // Remove NULL-bitmap
129
        $row = array();
130
        
131
        /** @var \Plasma\ColumnDefinitionInterface  $column */
132
        foreach($this->fields as $column) {
133
            if(\array_key_exists($column->getName(), $nullRow)) {
134
                $row[$column->getName()] = $nullRow[$column->getName()];
135
                continue;
136
            }
137
            
138
            $value = $this->stdDecodeBinaryValue($column, $buffer);
139
            $parsedValue = $column->parseValue($value);
140
            
141
            if($value !== $parsedValue) {
142
                $value = $parsedValue;
143
            }
144
            
145
            $row[$column->getName()] = $value;
146
        }
147
        
148
        return $row;
149
    }
150
    
151
    /**
152
     * Standard encode value, if type extensions failed.
153
     * @param mixed  $param
154
     * @return array
155
     * @throws \Plasma\Exception
156
     */
157
    protected function stdEncodeValue($param): array {
158
        $unsigned = false;
159
        
160
        switch(\gettype($param)) {
161
            case 'boolean':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
162
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY;
163
                $value = ($param ? "\x01" : "\0");
164
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
165
            case 'integer':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
166
                if($param >= 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
167
                    $unsigned = true;
168
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
169
                
170
                if($param >= 0 && $param < (1 << 15)) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
171
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT;
172
                    $value = \Plasma\BinaryBuffer::writeInt2($param);
173
                } elseif(\PHP_INT_SIZE === 4) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
174
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG;
175
                    $value = \Plasma\BinaryBuffer::writeInt4($param);
176
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
177
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG;
178
                    $value = \Plasma\BinaryBuffer::writeInt8($param);
179
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
180
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
181
            case 'double':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
182
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE;
183
                $value = \Plasma\BinaryBuffer::writeDouble($param);
184
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
185
            case 'string':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
186
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB;
187
                $value = \Plasma\BinaryBuffer::writeStringLength($param);
188
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
189
            case 'NULL':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
190
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL;
191
                $value = '';
192
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
193
            default:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
194
                throw new \Plasma\Exception('Unexpected type for binding parameter: '.\gettype($param));
195
            break;
196
        }
197
        
198
        return array($unsigned, $type, $value);
199
    }
200
    
201
    /**
202
     * Standard decode value, if type extensions failed.
203
     * @param \Plasma\ColumnDefinitionInterface  $column
204
     * @param \Plasma\BinaryBuffer               $buffer
205
     * @return mixed
206
     * @throws \Plasma\Exception
207
     */
208
    protected function stdDecodeBinaryValue(\Plasma\ColumnDefinitionInterface $column, \Plasma\BinaryBuffer $buffer) {
209
        $flags = $column->getFlags();
210
        
211
        switch(true) {
212
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
213
                $value = $buffer->readInt1();
214
                $value = $this->zeroFillInts($column, $value);
215
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
216
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
217
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_YEAR) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
218
                $value = $buffer->readInt2();
219
                $value = $this->zeroFillInts($column, $value);
220
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
221
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_INT24) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
222
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
223
                $value = $buffer->readInt4();
224
            
225
                if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) !== 0 && \PHP_INT_SIZE <= 4) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
226
                    $value = \bcadd($value, '18446744073709551616');
227
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
228
                
229
                $value = $this->zeroFillInts($column, $value);
230
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
231
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
232
                $value = $buffer->readInt8();
233
                
234
                if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) !== 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
235
                    $value = \bcadd($value, '18446744073709551616');
236
                } elseif(\PHP_INT_SIZE > 4) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
237
                    $value = (int) $value;
238
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
239
                
240
                $value = $this->zeroFillInts($column, $value);
241
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
242
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_FLOAT) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
243
                $value = $buffer->readFloat();
244
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
245
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
246
                $value = $buffer->readDouble();
247
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
248
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DATE) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
249
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NEWDATE) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
250
                $length = $buffer->readIntLength();
251
                if($length > 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
252
                    $year = $buffer->readInt2();
253
                    $month = $buffer->readInt1();
254
                    $day = $buffer->readInt1();
255
                    
256
                    $value = \sprintf('%d-%d-%d', $year, $month, $day);
257
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
258
                    $value = '0000-00-00';
259
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
260
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
261
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DATETIME) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
262
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TIMESTAMP) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
263
                $length = $buffer->readIntLength();
264
                if($length > 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
265
                    $year = $buffer->readInt2();
266
                    $month = $buffer->readInt1();
267
                    $day = $buffer->readInt1();
268
                    
269
                    if($length > 4) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
270
                        $hour = $buffer->readInt1();
271
                        $min = $buffer->readInt1();
272
                        $sec = $buffer->readInt1();
273
                    } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
274
                        $hour = 0;
275
                        $min = 0;
276
                        $sec = 0;
277
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
278
                    
279
                    if($length > 7) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
280
                        $micro = $buffer->readInt4();
281
                    } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
282
                        $micro = 0;
283
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
284
                    
285
                    $timestamp = (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TIMESTAMP) !== 0);
286
                    
287
                    $micro = \str_pad($micro, 6, '0', \STR_PAD_LEFT);
288
                    $micro = ($timestamp ? $micro : \number_format($micro, 0, '', ' '));
0 ignored issues
show
Bug introduced by
$micro of type string is incompatible with the type double expected by parameter $number of number_format(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

288
                    $micro = ($timestamp ? $micro : \number_format(/** @scrutinizer ignore-type */ $micro, 0, '', ' '));
Loading history...
289
                    
290
                    $value = \sprintf('%d-%d-%d %d:%d:%d'.($micro > 0 ? '.%s' : ''), $year, $month, $day, $hour, $min, $sec, $micro);
291
                    
292
                    if($timestamp) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
293
                        $value = \DateTime::createFromFormat('Y-m-d H:i:s'.($micro > 0 ? '.u' : ''), $value)->getTimestamp();
294
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
295
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
296
                    $value = '0000-00-00 00:00:00.000 000';
297
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
298
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
299
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TIME) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
300
                $length = $buffer->readIntLength();
301
                if($length > 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
302
                    $sign = $buffer->readInt1();
303
                    $days = $buffer->readInt4();
304
                    
305
                    if($sign === 1) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
306
                        $days *= -1;
307
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
308
                    
309
                    $hour = $buffer->readInt1();
310
                    $min = $buffer->readInt1();
311
                    $sec = $buffer->readInt1();
312
                    
313
                    if($length > 8) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
314
                        $micro = $buffer->readInt4();
315
                    } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
316
                        $micro = 0;
317
                    }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 20
Loading history...
318
                    
319
                    $micro = \str_pad($micro, 6, '0', \STR_PAD_LEFT);
320
                    $micro = \number_format($micro, 0, '', ' ');
321
                    
322
                    $value = \sprintf('%dd %d:%d:%d'.($micro > 0 ? '.%s' : ''), $days, $hour, $min, $sec, $micro);
323
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
324
                    $value = '0d 00:00:00';
325
                }
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
326
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
327
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
328
                $value = null;
329
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
330
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_STRING) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
331
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_VARCHAR) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
332
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_VAR_STRING) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
333
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_ENUM) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
334
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SET) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
335
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
336
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_MEDIUM_BLOB) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
337
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_BLOB) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
338
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY_BLOB) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
339
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_GEOMETRY) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
340
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_BIT) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
341
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DECIMAL) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
342
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NEWDECIMAL) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
343
            case (($flags & \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_JSON) !== 0):
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
344
            case ($column->getType() === 'VARSTRING'): // WTF is going on ?! flags = 0, type = VARSTRING
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
345
                $value = $buffer->readStringLength();
346
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
347
            default:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
348
                throw new \InvalidArgumentException('Unknown column type (flags: '.$flags.', type: '.$column->getType().')');
349
            break;
350
        }
351
        
352
        return $value;
353
    }
354
    
355
    /**
356
     * @param \Plasma\ColumnDefinitionInterface  $column
357
     * @param string|int                         $value
358
     * @return string|int
359
     */
360
    protected function zeroFillInts(\Plasma\ColumnDefinitionInterface $column, $value) {
361
        $flags = $column->getFlags();
362
        
363
        if(($flags & \Plasma\Drivers\MySQL\FieldFlags::ZEROFILL_FLAG) !== 0) {
364
            $value = \str_pad(((string) $value), $column->getLength(), '0', \STR_PAD_LEFT);
365
        }
366
        
367
        return $value;
368
    }
369
}
370