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.
Completed
Push — master ( bd87d2...776093 )
by Charlotte
03:49
created

LocalInFileRequestMessage::__construct()   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 1
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\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 3
    function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) {
27 3
        $this->parser = $parser;
28 3
    }
29
    
30
    /**
31
     * Get the identifier for the packet.
32
     * @return string
33
     */
34 1
    static function getID(): string {
35 1
        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()->then(null, function () {
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 1
    function getParser(): \Plasma\Drivers\MySQL\ProtocolParser {
70 1
        return $this->parser;
71
    }
72
    
73
    /**
74
     * Sets the parser state, if necessary. If not, return `-1`.
75
     * @return int
76
     */
77 1
    function setParserState(): int {
78 1
        return -1;
79
    }
80
    
81
    /**
82
     * Sends the contents to the server.
83
     * @param string $content
84
     * @return void
85
     */
86
    protected function sendFile(string $content): void {
87
        $this->parser->sendPacket($content);
88
        $this->parser->sendPacket('');
89
    }
90
}
91