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
Pull Request — master (#32)
by Charlotte
02:14
created

HandshakeResponseCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 7
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Plasma Driver MySQL component
4
 * Copyright 2018-2019 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
 * Handshake Response command.
14
 * @internal
15
 */
16
class HandshakeResponseCommand implements CommandInterface {
17
    use \Evenement\EventEmitterTrait;
18
    
19
    /**
20
     * @var \Plasma\Drivers\MySQL\ProtocolParser
21
     */
22
    protected $parser;
23
    
24
    /**
25
     * @var \Plasma\Drivers\MySQL\Messages\HandshakeMessage
26
     */
27
    protected $handshake;
28
    
29
    /**
30
     * @var int
31
     */
32
    protected $capability;
33
    
34
    /**
35
     * @var string|null
36
     */
37
    protected $plugin;
38
    
39
    /**
40
     * @var string
41
     */
42
    protected $user;
43
    
44
    /**
45
     * @var string
46
     */
47
    protected $password;
48
    
49
    /**
50
     * @var string
51
     */
52
    protected $database;
53
    
54
    /**
55
     * @var bool
56
     */
57
    protected $finished = false;
58
    
59
    /**
60
     * Constructor.
61
     * @param \Plasma\Drivers\MySQL\ProtocolParser             $parser
62
     * @param \Plasma\Drivers\MySQL\Messages\HandshakeMessage  $handshake
63
     * @param int                                              $capability
64
     * @param string|null                                      $plugin
65
     * @param string                                           $user
66
     * @param string                                           $password
67
     * @param string                                           $database
68
     */
69
    function __construct(
70
        \Plasma\Drivers\MySQL\ProtocolParser $parser, \Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake,
71
        int $capability, ?string $plugin, string $user, string $password, string $database
72
    ) {
73
        $this->parser = $parser;
74
        $this->handshake = $handshake;
75
        $this->capability = $capability;
76
        $this->plugin = $plugin;
77
        
78
        $this->user = $user;
79
        $this->password = $password;
80
        $this->database = $database;
81
    }
82
    
83
    /**
84
     * Get the encoded message for writing to the database connection.
85
     * @return string
86
     */
87
    function getEncodedMessage(): string {
88
        $maxPacketSize = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_MAX_PACKET_SIZE;
89
        $charsetNumber = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_CHARSET_NUMBER;
90
        
91
        $packet = \pack('VVc', $this->capability, $maxPacketSize, $charsetNumber);
92
        $packet .= \str_repeat("\x00", 23);
93
        $packet .= $this->user."\x00";
94
        
95
        if($this->plugin !== null) {
96
            $plug = $this->plugin;
97
            
98
            /** @var \Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface  $auth */
99
            $auth = new $plug($this->parser, $this->handshake);
100
            
101
            $packet .= $auth->getHandshakeAuth($this->password);
102
        }
103
        
104
        if($this->database !== '') {
105
            $packet .= $this->database."\x00";
106
        }
107
        
108
        if($this->plugin !== null) {
109
            $packet .= $this->handshake->authPluginName."\x00";
110
        }
111
        
112
        $this->finished = true;
113
        return $packet;
114
    }
115
    
116
    /**
117
     * Sets the parser state, if necessary. If not, return `-1`.
118
     * @return int
119
     */
120
    function setParserState(): int {
121
        return \Plasma\Drivers\MySQL\ProtocolParser::STATE_AUTH;
122
    }
123
    
124
    /**
125
     * Sets the command as completed. This state gets reported back to the user.
126
     * @return void
127
     */
128
    function onComplete(): void {
129
        $this->finished = true;
130
        $this->emit('end');
131
    }
132
    
133
    /**
134
     * Sets the command as errored. This state gets reported back to the user.
135
     * @param \Throwable  $throwable
136
     * @return void
137
     */
138
    function onError(\Throwable $throwable): void {
139
        $this->finished = true;
140
        $this->emit('error', array($throwable));
141
    }
142
    
143
    /**
144
     * Sends the next received value into the command.
145
     * @param mixed  $value
146
     * @return void
147
     */
148
    function onNext($value): void {
149
        // Nothing to do
150
    }
151
    
152
    /**
153
     * Whether the command has finished.
154
     * @return bool
155
     */
156
    function hasFinished(): bool {
157
        return $this->finished;
158
    }
159
    
160
    /**
161
     * Whether this command sets the connection as busy.
162
     * @return bool
163
     */
164
    function waitForCompletion(): bool {
165
        return true;
166
    }
167
    
168
    /**
169
     * Whether the sequence ID should be resetted.
170
     * @return bool
171
     */
172
    function resetSequence(): bool {
173
        return false;
174
    }
175
}
176