| Conditions | 17 |
| Paths | 254 |
| Total Lines | 95 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 45 |
| CRAP Score | 19.6955 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 249 | 13 | protected function processBuffer() { |
|
| 250 | 13 | \Plasma\Drivers\MySQL\Messages\MessageUtility::debug('ProtocolParser::processBuffer called'); |
|
| 251 | |||
| 252 | 13 | $buffer = $this->buffer; |
|
| 253 | |||
| 254 | 13 | $length = \Plasma\Drivers\MySQL\Messages\MessageUtility::readInt3($buffer); |
|
| 255 | 13 | $this->sequenceID = \Plasma\Drivers\MySQL\Messages\MessageUtility::readInt1($buffer); |
|
| 256 | |||
| 257 | 13 | $stmtExecuteCmd = ($this->currentCommand instanceof \Plasma\Drivers\MySQL\Commands\StatementExecuteCommand); |
|
| 258 | 13 | $isOKresponse = ($buffer[0] === "\x00" && $this->buffer[0] !== "\x00"); |
|
| 259 | |||
| 260 | 13 | if(!$stmtExecuteCmd) { |
|
| 261 | 13 | if(\strlen($buffer) < $length) { |
|
| 262 | \Plasma\Drivers\MySQL\Messages\MessageUtility::debug('returned, insufficent length: '.\strlen($buffer).', '.$length.' required'); |
||
| 263 | 13 | return; |
|
| 264 | } |
||
| 265 | } elseif(!$isOKresponse) { |
||
| 266 | $buffer = $this->buffer; |
||
| 267 | } |
||
| 268 | |||
| 269 | 13 | \Plasma\Drivers\MySQL\Messages\MessageUtility::debug('Read length and sequence'); |
|
| 270 | |||
| 271 | //var_dump(unpack('C*', substr($this->buffer, 10))); |
||
| 272 | |||
| 273 | /** @var \Plasma\Drivers\MySQL\Messages\MessageInterface $message */ |
||
| 274 | 13 | $message = null; |
|
| 275 | |||
| 276 | 13 | if($this->state === static::STATE_INIT) { |
|
| 277 | 13 | $message = new \Plasma\Drivers\MySQL\Messages\HandshakeMessage($this); |
|
| 278 | } else { |
||
| 279 | 11 | $firstChar = \Plasma\Drivers\MySQL\Messages\MessageUtility::readBuffer($buffer, 1); |
|
| 280 | 11 | \Plasma\Drivers\MySQL\Messages\MessageUtility::debug('Received Message char "'.$firstChar.'" (0x'.\dechex(\ord($firstChar)).') - buffer length: '.\strlen($buffer)); |
|
| 281 | |||
| 282 | switch(true) { |
||
| 283 | 11 | case ($firstChar === \Plasma\Drivers\MySQL\Messages\ErrResponseMessage::getID()): |
|
|
1 ignored issue
–
show
|
|||
| 284 | 1 | $message = new \Plasma\Drivers\MySQL\Messages\ErrResponseMessage($this); |
|
| 285 | 1 | break; |
|
|
1 ignored issue
–
show
|
|||
| 286 | 10 | case ($firstChar === \Plasma\Drivers\MySQL\Messages\EOFMessage::getID() && $length < 6): |
|
|
1 ignored issue
–
show
|
|||
| 287 | $message = new \Plasma\Drivers\MySQL\Messages\EOFMessage($this); |
||
| 288 | break; |
||
|
1 ignored issue
–
show
|
|||
| 289 | 10 | case ($this->currentCommand instanceof \Plasma\Drivers\MySQL\Commands\PrepareCommand && $firstChar === "\x00"): |
|
|
1 ignored issue
–
show
|
|||
| 290 | 1 | $message = new \Plasma\Drivers\MySQL\Messages\PrepareStatementOkMessage($this); |
|
| 291 | 1 | break; |
|
|
1 ignored issue
–
show
|
|||
| 292 | 10 | case ($isOKresponse): |
|
|
1 ignored issue
–
show
|
|||
| 293 | 10 | $message = new \Plasma\Drivers\MySQL\Messages\OkResponseMessage($this); |
|
| 294 | 10 | break; |
|
|
1 ignored issue
–
show
|
|||
| 295 | default: |
||
| 296 | 2 | if($this->parseCallback !== null) { |
|
|
1 ignored issue
–
show
|
|||
| 297 | $buffer = $firstChar.$buffer; |
||
| 298 | |||
| 299 | $parse = $this->parseCallback; |
||
| 300 | $this->parseCallback = null; |
||
| 301 | |||
| 302 | $buffer = $firstChar.$buffer; |
||
| 303 | |||
| 304 | $caller = new \Plasma\Drivers\MySQL\ProtocolOnNextCaller($this, $buffer); |
||
| 305 | $parse($caller); |
||
| 306 | |||
| 307 | $buffer = $caller->getBuffer(); |
||
| 308 | } else { |
||
| 309 | 2 | $buffer = $firstChar.$buffer; |
|
| 310 | |||
| 311 | 2 | $caller = new \Plasma\Drivers\MySQL\ProtocolOnNextCaller($this, $buffer); |
|
| 312 | 2 | $this->currentCommand->onNext($caller); |
|
| 313 | |||
| 314 | 2 | $buffer = $caller->getBuffer(); |
|
| 315 | } |
||
| 316 | 2 | break; |
|
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | 13 | if(!($message instanceof \Plasma\Drivers\MySQL\Messages\MessageInterface)) { |
|
| 321 | 2 | $this->buffer = $buffer; |
|
| 322 | |||
| 323 | 2 | if(\strlen($this->buffer) > 0) { |
|
| 324 | $this->driver->getLoop()->futureTick(function () { |
||
| 325 | 2 | $this->processBuffer(); |
|
| 326 | 2 | }); |
|
| 327 | } |
||
| 328 | |||
| 329 | 2 | return; |
|
| 330 | } |
||
| 331 | |||
| 332 | 13 | \Plasma\Drivers\MySQL\Messages\MessageUtility::debug('Received Message '.\get_class($message)); |
|
| 333 | |||
| 334 | 13 | $state = $message->setParserState(); |
|
| 335 | 13 | if($state !== -1) { |
|
| 336 | 13 | $this->state = $state; |
|
| 337 | } |
||
| 338 | |||
| 339 | 13 | if($message instanceof \Plasma\Drivers\MySQL\Messages\HandshakeMessage) { |
|
| 340 | 13 | $this->handshakeMessage = $message; |
|
| 341 | } |
||
| 342 | |||
| 343 | 13 | $this->handleMessage($buffer, $message); |
|
| 344 | 13 | } |
|
| 447 |