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.
Test Failed
Push — master ( d54200...f2da15 )
by Charlotte
03:55
created

StatementExecuteCommand::resetSequence()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
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\Drivers\MySQL\Messages\MessageUtility::writeInt4($this->id);
55
        
56
        $packet .= "\0"; // Cursor type flag
57
        $packet .= \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt4(1); // Iteration count is always 1
58
        
59
        $paramCount = \count($this->params);
60
        
61
        $bitmapOffset = \strlen($packet);
62
        $packet .= \str_repeat("\0", (($paramCount + 7) >> 3));
63
        
64
        $bound = 0;
65
        
66
        $types = '';
67
        $values = '';
68
        
69
        foreach($this->params as $id => $param) {
70
            if($param === null) {
71
                $offset = $bitmapOffset + ($id >> 3);
72
                $packet[$offset] = $packet[$offset] | \chr((1 << ($id % 8)));
73
            } else {
74
                $bound = 1;
75
            }
76
            
77
            $unsigned = false;
78
            
79
            try {
80
                $manager = \Plasma\Types\TypeExtensionsManager::getManager('driver-mysql');
81
                $encode = $manager->encodeType($param);
82
                
83
                $unsigned = $encode->isUnsigned();
84
                $type = $encode->getSQLType();
85
                $value = $encode->getValue();
86
            } catch (\Plasma\Exception $e) {
87
                [ $unsigned, $type, $value ] = $this->stdEncodeValue($param);
88
            }
89
            
90
            $types .= \chr($type);
91
            $types .= ($unsigned ? "\x80" : "\0");
92
            
93
            $values .= $value;
94
        }
95
        
96
        $packet .= \chr($bound);
97
        
98
        if($bound) {
99
            $packet .= $types;
100
            $packet .= $values;
101
        }
102
        
103
        return $packet;
104
    }
105
    
106
    /**
107
     * Parses the binary resultset row and returns the row.
108
     * @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...
109
     * @param string                             $buffer
0 ignored issues
show
Coding Style introduced by
Superfluous parameter comment
Loading history...
110
     * @return array
111
     */
112
    protected function parseResultsetRow(string &$buffer): array {
113
        var_dump(unpack('C*', $buffer));
0 ignored issues
show
Security Debugging Code introduced by
var_dump(unpack('C*', $buffer)) looks like debug code. Are you sure you do not want to remove it?
Loading history...
114
        //$buffer = \substr($buffer, 1); // Skip first byte (header)
115
        
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 = \substr($buffer, ((\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($columm->getName(), $nullRow)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columm seems to be never defined.
Loading history...
134
                $row[$columm->getName()] = $nullRow[$columm->getName()];
135
                continue;
136
            }
137
            
138
            $rawValue = \Plasma\Drivers\MySQL\Messages\MessageUtility::readStringLength($buffer);
139
            
140
            try {
141
                $value = $column->parseValue($rawValue);
142
            } catch (\Plasma\Exception $e) {
143
                $value = $this->stdDecodeValue($rawValue);
0 ignored issues
show
Bug introduced by
The call to Plasma\Drivers\MySQL\Com...mmand::stdDecodeValue() has too few arguments starting with param. ( Ignorable by Annotation )

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

143
                /** @scrutinizer ignore-call */ 
144
                $value = $this->stdDecodeValue($rawValue);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
$rawValue of type null|string is incompatible with the type Plasma\ColumnDefinitionInterface expected by parameter $column of Plasma\Drivers\MySQL\Com...mmand::stdDecodeValue(). ( Ignorable by Annotation )

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

143
                $value = $this->stdDecodeValue(/** @scrutinizer ignore-type */ $rawValue);
Loading history...
144
            }
145
            
146
            $row[$column->getName()] = $value;
147
        }
148
        
149
        return $row;
150
    }
151
    
152
    /**
153
     * Standard encode value, if type extensions failed.
154
     * @param mixed  $param
155
     * @return array
156
     * @throws \Plasma\Exception
157
     */
158
    protected function stdEncodeValue($param): array {
159
        $unsigned = false;
160
        
161
        switch(\gettype($param)) {
162
            case 'boolean':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
163
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY;
164
                $value = ($param ? "\x01" : "\0");
165
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
166
            case 'integer':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
167
                if($param >= 0) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
168
                    $unsigned = true;
169
                }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
170
                
171
                // TODO: Check if short, long or long long
172
                if($param >= 0 && $param < (1 << 15)) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
173
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT;
174
                    $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt2($param);
175
                } elseif(\PHP_INT_SIZE === 4) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
176
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG;
177
                    $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt4($param);
178
                } else {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
179
                    $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG;
180
                    $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt8($param);
181
                }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
182
            break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
183
            case 'double':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
184
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE;
185
                $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeFloat($param);
186
            break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
187
            case 'string':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
188
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB;
189
                
190
                $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt4(\strlen($param));
191
                $value .= $param;
192
            break;
0 ignored issues
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
193
            case 'NULL':
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
194
                $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL;
195
                $value = '';
196
            break;
1 ignored issue
show
Coding Style introduced by
Case breaking statement indented incorrectly; expected 16 spaces, found 12
Loading history...
197
            default:
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
198
                throw new \Plasma\Exception('Unexpected type for binding parameter: '.\gettype($param));
199
            break;
200
        }
201
        
202
        return array($unsigned, $type, $value);
203
    }
204
    
205
    /**
206
     * Whether the sequence ID should be resetted.
207
     * @return bool
208
     */
209
    function resetSequence(): bool {
210
        return false;
211
    }
212
}
213