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 ( 92425a...bdb42f )
by Cees-Jan
13s
created

AbstractLogglyLogger::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 17
ccs 10
cts 11
cp 0.9091
crap 2.003
rs 9.7
c 0
b 0
f 0
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\normalizeContext;
14
use function WyriHaximus\PSR3\processPlaceHolders;
15
16
abstract class AbstractLogglyLogger extends AbstractLogger
17
{
18 24
    public function log($level, $message, array $context = []): void
19
    {
20 24
        checkCorrectLogLevel($level);
21 22
        $this->send(
22 22
            $this->format($level, $message, $context)
23
        );
24 22
    }
25
26
    abstract protected function send(string $data);
27
28 22
    protected function format($level, $message, array $context): string
29
    {
30 22
        $message = (string)$message;
31 22
        $context = normalizeContext($context);
32 22
        $message = processPlaceHolders($message, $context);
33 22
        $json = \json_encode([
34 22
            'level'   => $level,
35 22
            'message' => $level . ' ' . $message,
36 22
            'context' => $context,
37
        ]);
38
39 22
        if ($json === false) {
40
            throw new InvalidArgumentException(\json_last_error_msg());
41
        }
42
43 22
        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