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 ( c84b74...6c770b )
by Charlotte
03:58
created

QueryCommand::getEncodedMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
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
 * Query command.
14
 * @internal
15
 */
16
class QueryCommand extends PromiseCommand {
17
    /**
18
     * The identifier for this command.
19
     * @var int
20
     * @source
21
     */
22
    const COMMAND_ID = 0x03;
23
    
24
    /**
25
     * @var string
26
     */
27
    protected $query;
28
    
29
    /**
30
     * @var \Plasma\ColumnDefinitionInterface[]
31
     */
32
    protected $fields = array();
33
    
34
    /**
35
     * @var int|null
36
     */
37
    protected $fieldsCount;
38
    
39
    /**
40
     * @var \Plasma\StreamQueryResult|\Plasma\QueryResult|null
41
     */
42
    protected $resolveValue;
43
    
44
    /**
45
     * Constructor.
46
     * @param \Plasma\DriverInterface  $driver
47
     * @param string                   $query
48
     */
49 4
    function __construct(\Plasma\DriverInterface $driver, string $query) {
50 4
        parent::__construct($driver);
51
        
52 4
        $this->driver = $driver;
53 4
        $this->query = $query;
54 4
    }
55
    
56
    /**
57
     * Get the encoded message for writing to the database connection.
58
     * @return string
59
     */
60 4
    function getEncodedMessage(): string {
61 4
        return \chr(static::COMMAND_ID).$this->query;
62
    }
63
    
64
    /**
65
     * Sends the next received value into the command.
66
     * @param mixed  $value
67
     * @return void
68
     */
69 4
    function onNext($value): void {
70 4
        if($value instanceof \Plasma\Drivers\MySQL\ProtocolOnNextCaller) {
71 3
            $this->handleQueryOnNextCaller($value);
72 3
        } elseif($value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage || $value instanceof \Plasma\Drivers\MySQL\Messages\EOFMessage) {
73 3
            if($this->resolveValue !== null) {
74
                $value->getParser()->markCommandAsFinished($this);
75 3
            } elseif($this->fieldsCount == 0 && $value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage) { // Matching 0 and null
1 ignored issue
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->fieldsCount of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
76 3
                $this->resolveValue = new \Plasma\QueryResult($value->affectedRows, $value->warningsCount, $value->lastInsertedID);
77 3
                $value->getParser()->markCommandAsFinished($this);
78
            } else {
79
                $this->createResolve();
80
            }
81
        }
82 4
    }
83
    
84
    /**
85
     * Handles query commands on next caller.
86
     * @param \Plasma\Drivers\MySQL\ProtocolOnNextCaller  $value
87
     * @return void
88
     */
89 3
    function handleQueryOnNextCaller(\Plasma\Drivers\MySQL\ProtocolOnNextCaller $value): void {
90 3
        $buffer = $value->getBuffer();
91 3
        $parser = $value->getParser();
92
        
93 3
        if($this->resolveValue !== null) {
94
            $row = $this->parseResultsetRow($buffer);
95
            $this->emit('data', array($row));
96
        } else {
97 3
            $field = $this->handleQueryOnNextCallerColumns($buffer, $parser);
98 3
            if($field) {
1 ignored issue
show
introduced by
$field is of type Plasma\ColumnDefinition, thus it always evaluated to true.
Loading history...
99 3
                $this->fields[$field->getName()] = $field;
100
            }
101
        }
102 3
    }
103
    
104
    /**
105
     * Creates the resolve value and resolves the promise.
106
     * @return void
107
     */
108
    function createResolve(): void {
109
        $this->resolveValue = new \Plasma\StreamQueryResult($this->driver, $this, 0, 0, $this->fields, null);
110
        $this->deferred->resolve($this->resolveValue);
111
    }
112
    
113
    /**
114
     * Whether the sequence ID should be resetted.
115
     * @return bool
116
     */
117 4
    function resetSequence(): bool {
118 4
        return true;
119
    }
120
}
121