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.
Failed Conditions
Push — master ( f2da15...888a68 )
by Charlotte
05:28
created

LocalInFileRequestMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
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\Messages;
11
12
/**
13
 * Represents a Local In File Data Message.
14
 * @internal
15
 */
16
class LocalInFileRequestMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface {
17
    /**
18
     * @var \Plasma\Drivers\MySQL\ProtocolParser
19
     */
20
    protected $parser;
21
    
22
    /**
23
     * Constructor.
24
     * @param \Plasma\Drivers\MySQL\ProtocolParser  $parser
25
     */
26
    function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) {
27
        $this->parser = $parser;
28
    }
29
    
30
    /**
31
     * Get the identifier for the packet.
32
     * @return string
33
     */
34
    static function getID(): string {
35
        return "\xFB";
36
    }
37
    
38
    /**
39
     * Parses the message, once the complete string has been received.
40
     * Returns false if not enough data has been received, or the remaining buffer.
41
     * @param \Plasma\BinaryBuffer  $buffer
42
     * @return bool
43
     * @throws \Plasma\Drivers\MySQL\Messages\ParseException
44
     */
45
    function parseMessage(\Plasma\BinaryBuffer $buffer): bool {
46
        $filesystem = \Plasma\Drivers\MySQL\DriverFactory::getFilesystem();
47
        
48
        if($filesystem !== null) {
49
            $filesystem->file($buffer->getContents())->getContents()->otherwise(function () {
0 ignored issues
show
Bug introduced by
The method otherwise() does not exist on React\Promise\PromiseInterface. It seems like you code against a sub-type of said class. However, the method does not exist in React\Promise\SimpleFulfilledTestPromise or React\Promise\SimpleRejectedTestPromise or React\Promise\CancellablePromiseInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

49
            $filesystem->file($buffer->getContents())->getContents()->/** @scrutinizer ignore-call */ otherwise(function () {
Loading history...
50
                return '';
51
            })->then(function (string $content) {
52
                $this->sendFile($content);
53
            });
54
        } else {
55
            if(\file_exists($buffer->getContents())) {
56
                $this->sendFile(\file_get_contents($buffer->getContents()));
57
            } else {
58
                $this->sendFile('');
59
            }
60
        }
61
        
62
        return true;
63
    }
64
    
65
    /**
66
     * Get the parser which created this message.
67
     * @return \Plasma\Drivers\MySQL\ProtocolParser
68
     */
69
    function getParser(): \Plasma\Drivers\MySQL\ProtocolParser {
70
        return $this->parser;
71
    }
72
    
73
    /**
74
     * Sets the parser state, if necessary. If not, return `-1`.
75
     * @return int
76
     */
77
    function setParserState(): int {
78
        return -1;
79
    }
80
    
81
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $content should have a doc-comment as per coding-style.
Loading history...
82
     * Sends the contents to the server.
83
     * @param string $contents
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $contents does not match actual variable name $content
Loading history...
84
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
85
    protected function sendFile(string $content) {
86
        $maxSize = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_MAX_PACKET_SIZE;
87
        
88
        for($size = \strlen($content); $size > 0; $size -= $maxSize) {
89
            $partial = \substr($content, 0, $maxSize);
90
            $content = \substr($content, $maxSize);
91
            
92
            $this->parser->sendPacket($partial);
93
            $partial = '';
1 ignored issue
show
Unused Code introduced by
The assignment to $partial is dead and can be removed.
Loading history...
94
        }
95
        
96
        $this->parser->sendPacket('');
97
    }
98
}
99