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
Branch cursor (62f708)
by Charlotte
04:14
created

FetchCommand::getEncodedMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
 * Fetch command.
14
 * @internal
15
 */
16
class FetchCommand extends StatementExecuteCommand {
17
    /**
18
     * The identifier for this command.
19
     * @var int
20
     * @source
21
     */
22
    const COMMAND_ID = 0x1C;
23
    
24
    /**
25
     * @var \Plasma\Drivers\MySQL\StatementCursor
26
     */
27
    protected $cursor;
28
    
29
    /**
30
     * @var int
31
     */
32
    protected $amount;
33
    
34
    /**
35
     * @var array
36
     */
37
    protected $rows = array();
38
    
39
    /**
40
     * Constructor.
41
     * @param \Plasma\DriverInterface                $driver
42
     * @param \Plasma\Drivers\MySQL\StatementCursor  $cursor
43
     * @param mixed                                  $id
44
     * @param string                                 $query
45
     * @param array                                  $params
46
     * @param \Plasma\ColumnDefinitionInterface[]    $paramsDef
47
     * @param int                                    $amount
48
     */
49 1
    function __construct(\Plasma\DriverInterface $driver, \Plasma\Drivers\MySQL\StatementCursor $cursor, $id, string $query, array $params, array $paramsDef, int $amount) {
50 1
        parent::__construct($driver, $id, $query, $params, $paramsDef, 0);
51
        
52 1
        $this->cursor = $cursor;
53 1
        $this->amount = $amount;
54
        
55
        $this->on('data', function ($row) {
56
            $this->rows[] = $row;
57 1
        });
58
        
59 1
        $this->removeAllListeners('end');
60
        $this->once('end', function () {
61
            // Let the event loop read the stream buffer before resolving
62
            $this->driver->getLoop()->futureTick(function () {
63
                // Unwrap if we only have one row
64
                $rows = (\count($this->rows) === 1 ? \reset($this->rows) : $this->rows);
0 ignored issues
show
Unused Code introduced by
The assignment to $rows is dead and can be removed.
Loading history...
65
                
66
                $this->deferred->resolve($this->rows);
67
                $this->rows = null;
68
            });
69 1
        });
70 1
    }
71
    
72
    /**
73
     * Get the encoded message for writing to the database connection.
74
     * @return string
75
     */
76 1
    function getEncodedMessage(): string {
77 1
        $packet = \chr(static::COMMAND_ID);
78 1
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->id);
79 1
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->amount);
80
        
81 1
        return $packet;
82
    }
83
    
84
    /**
85
     * Sends the next received value into the command.
86
     * @param mixed  $value
87
     * @return void
88
     */
89
    function onNext($value): void {
90
        if($value instanceof \Plasma\Drivers\MySQL\ProtocolOnNextCaller) {
91
            $this->handleQueryOnNextCaller($value);
92
        } elseif($value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage || $value instanceof \Plasma\Drivers\MySQL\Messages\EOFMessage) {
93
            $this->cursor->processOkMessage($value);
94
            $value->getParser()->markCommandAsFinished($this);
95
        }
96
    }
97
}
98