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.

LocalInFileRequestMessage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parseMessage() 0 18 3
A __construct() 0 2 1
A setParserState() 0 2 1
A getParser() 0 2 1
A sendFile() 0 3 1
A getID() 0 2 1
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\Messages;
11
12
/**
13
 * Represents a Local In File Data Message.
14
 */
15
class LocalInFileRequestMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface {
16
    /**
17
     * @var \Plasma\Drivers\MySQL\ProtocolParser
18
     */
19
    protected $parser;
20
    
21
    /**
22
     * Constructor.
23
     * @param \Plasma\Drivers\MySQL\ProtocolParser  $parser
24
     * @internal
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
     * @internal
34
     */
35 49
    static function getID(): string {
36 49
        return "\xFB";
37
    }
38
    
39
    /**
40
     * Parses the message, once the complete string has been received.
41
     * Returns false if not enough data has been received, or the remaining buffer.
42
     * @param \Plasma\BinaryBuffer  $buffer
43
     * @return bool
44
     * @throws \Plasma\Drivers\MySQL\Messages\ParseException
45
     * @internal
46
     */
47 1
    function parseMessage(\Plasma\BinaryBuffer $buffer): bool {
48 1
        $filesystem = \Plasma\Drivers\MySQL\DriverFactory::getFilesystem();
49
        
50 1
        if($filesystem !== null) {
51
            $filesystem->file($buffer->getContents())->getContents()->then(function (string $content) {
52
                $this->sendFile($content);
53
            }, function () {
54
                $this->parser->sendPacket('');
55
            });
56
        } else {
57 1
            if(\file_exists($buffer->getContents())) {
58 1
                $this->sendFile(\file_get_contents($buffer->getContents()));
59
            } else {
60
                $this->parser->sendPacket('');
61
            }
62
        }
63
        
64 1
        return true;
65
    }
66
    
67
    /**
68
     * Get the parser which created this message.
69
     * @return \Plasma\Drivers\MySQL\ProtocolParser
70
     * @internal
71
     */
72 1
    function getParser(): \Plasma\Drivers\MySQL\ProtocolParser {
73 1
        return $this->parser;
74
    }
75
    
76
    /**
77
     * Sets the parser state, if necessary. If not, return `-1`.
78
     * @return int
79
     * @internal
80
     */
81 1
    function setParserState(): int {
82 1
        return -1;
83
    }
84
    
85
    /**
86
     * Sends the contents to the server.
87
     * @param string $content
88
     * @return void
89
     */
90 1
    protected function sendFile(string $content): void {
91 1
        $this->parser->sendPacket($content);
92 1
        $this->parser->sendPacket('');
93 1
    }
94
}
95