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

StatementCursor::__destruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 6
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;
11
12
/**
13
 * Represents a Statement Cursor.
14
 */
15
class StatementCursor {
16
    /**
17
     * @var \Plasma\Drivers\MySQL\Driver
18
     */
19
    protected $driver;
20
    
21
    /**
22
     * @var \Plasma\Drivers\MySQL\Statement
23
     */
24
    protected $statement;
25
    
26
    /**
27
     * @var bool
28
     */
29
    protected $closed = false;
30
    
31
    /**
32
     * Constructor.
33
     * @param \Plasma\Drivers\MySQL\Driver     $driver
34
     * @param \Plasma\Drivers\MySQL\Statement  $statement
35
     */
36 1
    function __construct(\Plasma\Drivers\MySQL\Driver $driver, \Plasma\Drivers\MySQL\Statement $statement) {
37 1
        $this->driver = $driver;
38 1
        $this->statement = $statement;
39 1
    }
40
    
41
    /**
42
     * Destructor. Runs once the instance goes out of scope.
43
     * Please do not rely on the destructor to properly close your cursor.
44
     * ALWAYS explicitely close the cursor once you're done.
45
     * @throws \Plasma\Exception
46
     * @codeCoverageIgnore
47
     */
48
    function __destruct() {
49
        if(!$this->closed) {
50
            $this->close()->then(null, function () {
51
                // Error during implicit close, close the session
52
                $this->driver->close();
53
            });
54
        }
55
    }
56
    
57
    /**
58
     * Whether the cursor has been closed.
59
     * @return bool
60
     */
61
    function isClosed(): bool {
62
        return $this->closed;
63
    }
64
    
65
    /**
66
     * Closes the cursor and frees the associated resources on the server.
67
     * Closing a cursor more than once has no effect.
68
     * @return \React\Promise\PromiseInterface
69
     */
70
    function close(): \React\Promise\PromiseInterface {
71
        if($this->closed) {
72
            return \React\Promise\resolve();
73
        }
74
        
75
        $this->closed = true;
76
        
77
        return $this->statement->close();
78
    }
79
    
80
    /**
81
     * Fetches the given amount of rows using the cursor. Resolves with the row, an array of rows (if amount > 1), or false if no more results exist.
82
     * @param int  $amount
83
     * @return \React\Promise\PromiseInterface
84
     * @throws \Plasma\Exception  Thrown if the underlying statement has been closed.
85
     */
86 1
    function fetch(int $amount = 1): \React\Promise\PromiseInterface {
87 1
        if($this->closed) {
88
            return \React\Promise\resolve(false);
89 1
        } elseif($this->statement->isClosed()) {
90
            throw new \Plasma\Exception('Underlying statement has been closed');
91
        }
92
        
93 1
        $fetch = new \Plasma\Drivers\MySQL\Commands\FetchCommand(
94 1
            $this->driver,
95 1
            $this,
96 1
            $this->statement->getID(),
97 1
            $this->statement->getQuery(),
98 1
            $this->statement->getParams(),
99 1
            array(),
100 1
            $amount
101
        );
102 1
        $this->driver->executeCommand($fetch);
103
        
104 1
        return $fetch->getPromise();
105
    }
106
    
107
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $message should have a doc-comment as per coding-style.
Loading history...
108
     * Processes the OK or EOF message.
109
     * @param \Plasma\Drivers\MySQL\Messages\OkResponseMessage|\Plasma\Drivers\MySQL\Messages\EOFMessage
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
110
     * @return void
111
     * @internal
112
     */
113
    function processOkMessage($message): void {
114
        if(($message->statusFlags & \Plasma\Drivers\MySQL\StatusFlags::SERVER_MORE_RESULTS_EXISTS) === 0) {
115
            $this->close()->then(null, function (\Throwable $e) {
116
                $this->driver->emit('error', $e);
0 ignored issues
show
Bug introduced by
$e of type Throwable is incompatible with the type array expected by parameter $arguments of Plasma\Drivers\MySQL\Driver::emit(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

116
                $this->driver->emit('error', /** @scrutinizer ignore-type */ $e);
Loading history...
117
            });
118
        }
119
    }
120
}
121