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 ( c37035...b938cb )
by Charlotte
03:14 queued 21s
created

StatementExecuteCommand::getEncodedMessage()   B

Complexity

Conditions 6
Paths 42

Size

Total Lines 46
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 6.0397

Importance

Changes 0
Metric Value
cc 6
eloc 30
nc 42
nop 0
dl 0
loc 46
ccs 26
cts 29
cp 0.8966
crap 6.0397
rs 8.8177
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 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
                $encode = \Plasma\Types\TypeExtensionsManager::getManager('driver-mysql')
77 36
                    ->encodeType($param);
78
                
79
                $unsigned = $encode->isUnsigned();
80
                $type = $encode->getSQLType();
81
                $value = $encode->getValue();
82 36
            } catch (\Plasma\Exception $e) {
83 36
                [ $unsigned, $type, $value ] = \Plasma\Drivers\MySQL\BinaryProtocolValues::encode($param);
84
            }
85
            
86 35
            $types .= \chr($type).($unsigned ? "\x80" : "\x00");
87 35
            $values .= $value;
88
        }
89
        
90 35
        $packet .= \chr($bound);
91
        
92 35
        if($bound) {
93 35
            $packet .= $types;
94 35
            $packet .= $values;
95
        }
96
        
97 35
        return $packet;
98
    }
99
    
100
    /**
101
     * Whether the sequence ID should be resetted.
102
     * @return bool
103
     */
104 36
    function resetSequence(): bool {
105 36
        return true;
106
    }
107
    
108
    /**
109
     * Parses the binary resultset row and returns the row.
110
     * @param \Plasma\BinaryBuffer  $buffer
111
     * @return array
112
     */
113 35
    protected function parseResultsetRow(\Plasma\BinaryBuffer $buffer): array {
114 35
        $buffer->read(1); // remove packet header
115
        
116 35
        $nullRow = array();
117 35
        $i = 0;
118
        
119
        /** @var \Plasma\ColumnDefinitionInterface  $column */
120 35
        foreach($this->fields as $column) { // Handle NULL-bitmap
121 35
            if((\ord($buffer[(($i + 2) >> 3)]) & (1 << (($i + 2) % 8))) !== 0) {
122 2
                $nullRow[$column->getName()] = null;
123
            }
124
            
125 35
            $i++;
126
        }
127
        
128 35
        $buffer->read(((\count($this->fields) + 9) >> 3)); // Remove NULL-bitmap
129 35
        $row = array();
130
        
131
        /** @var \Plasma\ColumnDefinitionInterface  $column */
132 35
        foreach($this->fields as $column) {
133 35
            if(\array_key_exists($column->getName(), $nullRow)) {
134 2
                $row[$column->getName()] = null;
135 2
                continue;
136
            }
137
            
138
            try {
139 35
                $value = \Plasma\Types\TypeExtensionsManager::getManager('driver-mysql')
140 35
                    ->decodeType($column->getType(), $buffer)
141
                    ->getValue();
142 35
            } catch (\Plasma\Exception $e) {
143 35
                $value = \Plasma\Drivers\MySQL\BinaryProtocolValues::decode($column, $buffer);
144
            }
145
            
146 35
            $row[$column->getName()] = $value;
147
        }
148
        
149 35
        return $row;
150
    }
151
}
152