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 ( 9c2e1a...1f7860 )
by Cees-Jan
15:23 queued 12:04
created

LogglyBulkLogger::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\PSR3\Loggly;
4
5
use React\EventLoop\LoopInterface;
6
use React\EventLoop\Timer\TimerInterface;
7
use React\HttpClient\Client;
8
9
final class LogglyBulkLogger extends AbstractLogglyLogger
10
{
11
    const LF = "\r\n";
12
    const MAX_BODY_LENGTH = 5242880;
13
    const MAX_LINE_LENGTH = 1048576;
14
15
    /**
16
     * @var LoopInterface
17
     */
18
    private $loop;
19
20
    /**
21
     * @var Client
22
     */
23
    private $httpClient;
24
25
    /**
26
     * @var string
27
     */
28
    private $token;
29
30
    /**
31
     * @var float
32
     */
33
    private $timeout;
34
35
    /**
36
     * @var string[]
37
     */
38
    private $buffer = [];
39
40
    /**
41
     * @var int
42
     */
43
    private $bufferSize = 0;
44
45
    /**
46
     * @var TimerInterface
47
     */
48
    private $timer;
49
50
    private function __construct(LoopInterface $loop, Client $httpClient, string $token, float $timeout)
51
    {
52
        $this->loop = $loop;
53
        $this->httpClient = $httpClient;
54
        $this->token = $token;
55
        $this->timeout = $timeout;
56
    }
57
58
    public static function create(LoopInterface $loop, string $token, float $timeout = 5.3): self
59
    {
60
        $httpClient = self::createHttpClient($loop);
61
62
        return new self($loop, $httpClient, $token, $timeout);
63
    }
64
65
    public static function createFromHttpClient(
66
        LoopInterface $loop,
67
        Client $httpClient,
68
        string $token,
69
        float $timeout = 5.3
70
    ): self {
71
        return new self($loop, $httpClient, $token, $timeout);
72
    }
73
74
    protected function send(string $data): void
75
    {
76
        $dataLength = \strlen($data . self::LF);
77
        if ($dataLength > self::MAX_LINE_LENGTH) {
78
            return;
79
        }
80
81
        if ($this->bufferSize + $dataLength > self::MAX_BODY_LENGTH) {
82
            $this->sendBulk();
83
        }
84
85
        $this->buffer[] = $data;
86
        $this->bufferSize += $dataLength;
87
        $this->ensureTimer();
88
    }
89
90
    private function ensureTimer(): void
91
    {
92
        if ($this->timer instanceof TimerInterface) {
0 ignored issues
show
Bug introduced by
The class React\EventLoop\Timer\TimerInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
93
            return;
94
        }
95
96
        $this->timer = $this->loop->addTimer($this->timeout, function (): void {
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->loop->addTimer($t... $this->sendBulk(); }) of type object<React\EventLoop\TimerInterface> is incompatible with the declared type object<React\EventLoop\Timer\TimerInterface> of property $timer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
            $this->timer = null;
98
            $this->sendBulk();
99
        });
100
    }
101
102
    private function sendBulk(): void
103
    {
104
        if ($this->timer instanceof TimerInterface) {
0 ignored issues
show
Bug introduced by
The class React\EventLoop\Timer\TimerInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
105
            $this->timer->cancel();
106
            $this->timer = null;
107
        }
108
109
        $data = \implode(self::LF, $this->buffer);
110
111
        $this->buffer = [];
112
        $this->bufferSize = 0;
113
114
        $this->httpClient->request(
115
            'POST',
116
            'https://logs-01.loggly.com/bulk/' . $this->token,
117
            [
118
                'Content-Type' => 'application/json',
119
                'Content-Length' => \strlen($data),
120
            ],
121
            '1.1'
122
        )->end($data);
123
    }
124
}
125