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 ( 4a950a...a1aef1 )
by Cees-Jan
03:54
created

AbstractLogglyLogger::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
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 26
    public function log($level, $message, array $context = [])
19
    {
20 26
        checkCorrectLogLevel($level);
21 24
        $this->send(
22 24
            $this->format($level, $message, $context)
23
        );
24 22
    }
25
26
    abstract protected function send(string $data);
27
28 24
    protected function format($level, $message, array $context): string
29
    {
30 24
        $message = (string)$message;
31 24
        $context = normalizeContext($context);
32 24
        $message = processPlaceHolders($message, $context);
33 24
        $json = json_encode([
34 24
            'level'   => $level,
35 24
            'message' => $level . ' ' . $message,
36 24
            'context' => $context,
37
        ]);
38
39 24
        if ($json === false) {
40 2
            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