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 ( 14d15b...4a0e4b )
by Charlotte
03:19
created

LocalInFileRequestMessage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 73
ccs 18
cts 22
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A setParserState() 0 2 1
A getParser() 0 2 1
A getID() 0 2 1
A parseMessage() 0 18 3
A sendFile() 0 3 1
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 4
    function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) {
27 4
        $this->parser = $parser;
28 4
    }
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 1
    function parseMessage(\Plasma\BinaryBuffer $buffer): bool {
46 1
        $filesystem = \Plasma\Drivers\MySQL\DriverFactory::getFilesystem();
47
        
48 1
        if($filesystem !== null) {
49
            $filesystem->file($buffer->getContents())->getContents()->then(function (string $content) {
50
                $this->sendFile($content);
51
            }, function () {
52
                $this->parser->sendPacket('');
53
            });
54
        } else {
55 1
            if(\file_exists($buffer->getContents())) {
56 1
                $this->sendFile(\file_get_contents($buffer->getContents()));
57
            } else {
58
                $this->parser->sendPacket('');
59
            }
60
        }
61
        
62 1
        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 1
    protected function sendFile(string $content): void {
87 1
        $this->parser->sendPacket($content);
88 1
        $this->parser->sendPacket('');
89 1
    }
90
}
91