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 ( 18c025...2702d5 )
by Charlotte
03:32
created

ErrResponseMessage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 8.33%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 91
ccs 2
cts 24
cp 0.0833
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getParser() 0 2 1
A setParserState() 0 2 1
A __construct() 0 2 1
A getID() 0 2 1
A parseMessage() 0 22 4
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 an Err Response Message.
14
 * @internal
15
 */
16
class ErrResponseMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface {
17
    /**
18
     * Error code.
19
     * @var int
20
     */
21
    public $errorCode;
22
    
23
    /**
24
     * SQL State marker, if any.
25
     * @var string|null
26
     */
27
    public $sqlStateMarker;
28
    
29
    /**
30
     * SQL State, if any.
31
     * @var string|null
32
     */
33
    public $sqlState;
34
    
35
    /**
36
     * Error message.
37
     * @var string
38
     */
39
    public $errorMessage;
40
    
41
    /**
42
     * @var \Plasma\Drivers\MySQL\ProtocolParser
43
     */
44
    protected $parser;
45
    
46
    /**
47
     * Constructor.
48
     * @param \Plasma\Drivers\MySQL\ProtocolParser  $parser
49
     */
50
    function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) {
51
        $this->parser = $parser;
52
    }
53
    
54
    /**
55
     * Get the identifier for the packet.
56
     * @return string
57
     */
58 1
    static function getID(): string {
59 1
        return "\xFF";
60
    }
61
    
62
    /**
63
     * Parses the message, once the complete string has been received.
64
     * Returns false if not enough data has been received, or the remaining buffer.
65
     * @param string  $buffer
66
     * @return string|bool
67
     * @throws \Plasma\Drivers\MySQL\Messages\ParseException
68
     */
69
    function parseMessage(string $buffer) {
70
        $nameLength = \strpos($buffer, "\x00");
71
        if($nameLength === false) {
72
            return false;
73
        }
74
        
75
        $this->errorCode = \Plasma\Drivers\MySQL\Messages\MessageUtility::readInt2($buffer);
76
        
77
        $handshake = $this->parser->getHandshakeMessage();
78
        if(!$handshake || $this->parser->getState() == \Plasma\Drivers\MySQL\ProtocolParser::STATE_HANDSHAKE) {
79
            $exception = new \Plasma\Drivers\MySQL\Messages\ParseException($buffer, $this->errorCode);
80
            $exception->setState(\Plasma\Drivers\MySQL\ProtocolParser::STATE_HANDSHAKE_ERROR);
81
            $exception->setBuffer('');
82
            
83
            throw $exception;
84
        }
85
        
86
        $this->sqlStateMarker = \Plasma\Drivers\MySQL\Messages\MessageUtility::readStringLength($buffer, 1);
87
        $this->sqlState = \Plasma\Drivers\MySQL\Messages\MessageUtility::readStringLength($buffer, 5);
88
        $this->errorMessage = $buffer;
89
        
90
        return '';
91
    }
92
    
93
    /**
94
     * Get the parser which created this message.
95
     * @return \Plasma\Drivers\MySQL\ProtocolParser
96
     */
97
    function getParser(): \Plasma\Drivers\MySQL\ProtocolParser {
98
        return $this->parser;
99
    }
100
    
101
    /**
102
     * Sets the parser state, if necessary. If not, return `-1`.
103
     * @return int
104
     */
105
    function setParserState(): int {
106
        return \Plasma\Drivers\MySQL\ProtocolParser::STATE_OK;
107
    }
108
}
109