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 ( d13c9c...463153 )
by Charlotte
03:30
created

OkResponseMessage::parseMessage()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 44
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 5.3906

Importance

Changes 0
Metric Value
cc 5
eloc 29
nc 5
nop 1
dl 0
loc 44
ccs 21
cts 28
cp 0.75
crap 5.3906
rs 9.1448
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\Messages;
11
12
/**
13
 * Represents a Ok Response Message.
14
 * @internal
15
 */
16
class OkResponseMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface {
17
    /**
18
     * Count of affected rows by the last query.
19
     * @var int
20
     */
21
    public $affectedRows;
22
    
23
    /**
24
     * Last inserted ID by the last `INSERT` query.
25
     * @var int
26
     */
27
    public $lastInsertedID;
28
    
29
    /**
30
     * The server status flags.
31
     * @var int
32
     * @see \Plasma\Drivers\MySQL\StatusFlags
33
     */
34
    public $statusFlags;
35
    
36
    /**
37
     * Count of warnings.
38
     * @var int
39
     */
40
    public $warningsCount;
41
    
42
    /**
43
     * Server session information, if any.
44
     * @var string|null
45
     */
46
    public $sessionInfo;
47
    
48
    /**
49
     * Server session state changes, if any.
50
     * @var string|null
51
     */
52
    public $sessionStateChanges;
53
    
54
    /**
55
     * Human readable status information, if any.
56
     * @var string|null
57
     */
58
    public $info;
59
    
60
    /**
61
     * @var \Plasma\Drivers\MySQL\ProtocolParser
62
     */
63
    protected $parser;
64
    
65
    /**
66
     * Constructor.
67
     * @param \Plasma\Drivers\MySQL\ProtocolParser  $parser
68
     */
69 9
    function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) {
70 9
        $this->parser = $parser;
71 9
    }
72
    
73
    /**
74
     * Get the identifier for the packet.
75
     * @return string
76
     */
77 12
    static function getID(): string {
78 12
        return "\x00";
79
    }
80
    
81
    /**
82
     * Parses the message, once the complete string has been received.
83
     * Returns false if not enough data has been received, or the remaining buffer.
84
     * @param string  $buffer
85
     * @return string|bool
86
     * @throws \Plasma\Drivers\MySQL\Messages\ParseException
87
     */
88 9
    function parseMessage(string $buffer) {
89 9
        $nameLength = \strpos($buffer, "\x00");
90 9
        if($nameLength === false) {
91
            return false;
92
        }
93
        
94 9
        $affectedRows = \Plasma\Drivers\MySQL\Messages\MessageUtility::readIntLength($buffer);
95 9
        $lastInsertedID = \Plasma\Drivers\MySQL\Messages\MessageUtility::readIntLength($buffer);
96
        
97 9
        $handshake = $this->parser->getHandshakeMessage();
98 9
        if(!$handshake) {
99
            throw new \Plasma\Drivers\MySQL\Messages\ParseException('No handshake message when receiving ok response packet');
100
        }
101
        
102 9
        $statusFlags = \Plasma\Drivers\MySQL\Messages\MessageUtility::readInt2($buffer);
103 9
        $warningsCount = \Plasma\Drivers\MySQL\Messages\MessageUtility::readInt2($buffer);
104
        
105 9
        if(($handshake->capability & \Plasma\Drivers\MySQL\CapabilityFlags::CLIENT_SESSION_TRACK) !== 0) {
106
            $sessionInfo = \Plasma\Drivers\MySQL\Messages\MessageUtility::readStringLength($buffer);
107
            
108
            if(($statusFlags & \Plasma\Drivers\MySQL\StatusFlags::SERVER_SESSION_STATE_CHANGED) !== 0) {
109
                $sessionStateChanges = \Plasma\Drivers\MySQL\Messages\MessageUtility::readStringLength($buffer);
110
            } else {
111
                $sessionStateChanges = null;
112
            }
113
            
114
            $info = null;
115
        } else {
116 9
            $sessionInfo = null;
117 9
            $sessionStateChanges = null;
118 9
            $info = $buffer;
119
        }
120
        
121 9
        $this->affectedRows = $affectedRows;
122 9
        $this->lastInsertedID = $lastInsertedID;
123
        
124 9
        $this->statusFlags = $statusFlags;
125 9
        $this->warningsCount = $warningsCount;
126
        
127 9
        $this->sessionInfo = $sessionInfo;
128 9
        $this->sessionStateChanges = $sessionStateChanges;
129 9
        $this->info = $info;
130
        
131 9
        return $buffer;
132
    }
133
    
134
    /**
135
     * Get the parser which created this message.
136
     * @return \Plasma\Drivers\MySQL\ProtocolParser
137
     */
138 2
    function getParser(): \Plasma\Drivers\MySQL\ProtocolParser {
139 2
        return $this->parser;
140
    }
141
    
142
    /**
143
     * Sets the parser state, if necessary. If not, return `-1`.
144
     * @return int
145
     */
146 9
    function setParserState(): int {
147 9
        return \Plasma\Drivers\MySQL\ProtocolParser::STATE_OK;
148
    }
149
}
150