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 ( b4dd81...80eb77 )
by Charlotte
03:13
created

FetchCommand::onNext()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 1
dl 0
loc 6
ccs 6
cts 6
cp 1
crap 4
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 \Plasma\ColumnDefinitionInterface[]    $fields
48
     * @param int                                    $amount
49
     */
50 1
    function __construct(
51
        \Plasma\DriverInterface $driver,
52
        \Plasma\Drivers\MySQL\StatementCursor $cursor,
53
        $id,
54
        string $query,
55
        array $params,
56
        array $paramsDef,
57
        array $fields,
58
        int $amount
59
    ) {
60 1
        parent::__construct($driver, $id, $query, $params, $paramsDef, 0);
61
        
62 1
        $this->cursor = $cursor;
63 1
        $this->fields = $fields;
64 1
        $this->amount = $amount;
65
        
66
        $this->on('data', function ($row) {
67 1
            $this->rows[] = $row;
68 1
        });
69
        
70 1
        $this->removeAllListeners('end');
71
        $this->once('end', function () {
72
            // Let the event loop read the stream buffer before resolving
73
            $this->driver->getLoop()->futureTick(function () {
74
                // Unwrap if we only have one row
75 1
                $crows = \count($this->rows);
76 1
                $rows = ($crows === 1 ? \reset($this->rows) : ($crows === 0 ? false : $this->rows));
77
                
78 1
                $this->deferred->resolve($rows);
79 1
                $this->rows = null;
80 1
            });
81 1
        });
82 1
    }
83
    
84
    /**
85
     * Get the encoded message for writing to the database connection.
86
     * @return string
87
     */
88 1
    function getEncodedMessage(): string {
89 1
        $packet = \chr(static::COMMAND_ID);
90 1
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->id);
91 1
        $packet .= \Plasma\BinaryBuffer::writeInt4($this->amount);
92
        
93 1
        return $packet;
94
    }
95
    
96
    /**
97
     * Sends the next received value into the command.
98
     * @param mixed  $value
99
     * @return void
100
     */
101 1
    function onNext($value): void {
102 1
        if($value instanceof \Plasma\Drivers\MySQL\ProtocolOnNextCaller) {
103 1
            $this->handleQueryOnNextCaller($value);
104 1
        } elseif($value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage || $value instanceof \Plasma\Drivers\MySQL\Messages\EOFMessage) {
105 1
            $this->cursor->processOkMessage($value);
106 1
            $value->getParser()->markCommandAsFinished($this);
107
        }
108 1
    }
109
}
110