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

AbstractLogglyLogger::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 11
cp 0
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\PSR3\Loggly;
4
5
use Psr\Log\AbstractLogger;
6
use Psr\Log\InvalidArgumentException;
7
use React\Dns\Resolver\Factory as ResolverFactory;
8
use React\EventLoop\LoopInterface;
9
use React\HttpClient\Client;
10
use React\HttpClient\Factory as HttpClientFactory;
11
use React\Socket\Connector;
12
use function WyriHaximus\PSR3\checkCorrectLogLevel;
13
use function WyriHaximus\PSR3\normalizeContextWithFormatValue;
14
use function WyriHaximus\PSR3\processPlaceHolders;
15
16
abstract class AbstractLogglyLogger extends AbstractLogger
17
{
18 2
    public function log($level, $message, array $context = []): void
19
    {
20 2
        checkCorrectLogLevel($level);
21
        $this->send(
22
            $this->format($level, $message, $context)
23
        );
24
    }
25
26
    abstract protected function send(string $data);
27
28
    protected function format($level, $message, array $context): string
29
    {
30
        $message = (string)$message;
31
        $context = normalizeContextWithFormatValue($context);
32
        $message = processPlaceHolders($message, $context);
33
        $json = \json_encode([
34
            'level'   => $level,
35
            'message' => $level . ' ' . $message,
36
            'context' => $context,
37
        ]);
38
39
        if ($json === false) {
40
            throw new InvalidArgumentException(\json_last_error_msg());
41
        }
42
43
        return $json;
44
    }
45
46 4
    protected static function createHttpClient(LoopInterface $loop): Client
47
    {
48 4
        $resolverFactory = new ResolverFactory();
49 4
        $resolver = $resolverFactory->createCached('8.8.8.8', $loop);
50
51 4
        if (\class_exists(HttpClientFactory::class)) {
52
            $factory = new HttpClientFactory();
53
54
            return $factory->create($loop, $resolver);
55
        }
56
57 4
        return new Client(
58 4
            $loop,
59 4
            new Connector(
60 4
                $loop,
61
                [
62 4
                    'dns' => $resolver,
63
                ]
64
            )
65
        );
66
    }
67
}
68