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 ( 461314...cac060 )
by Cees-Jan
01:31
created

Factory::create()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 40
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3.4437

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 19
cts 30
cp 0.6333
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 31
nc 2
nop 3
crap 3.4437
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\PSR15MiddlewareGroup;
4
5
use FriendsOfReact\Http\Middleware\Psr15Adapter\GroupedPSR15Middleware;
6
use Middlewares\AccessLog;
7
use Middlewares\ClientIp;
8
use Middlewares\Expires;
9
use Middlewares\ResponseTime;
10
use Middlewares\Uuid;
11
use Psr\Http\Message\ResponseInterface;
12
use Psr\Http\Message\ServerRequestInterface;
13
use Psr\Log\LoggerInterface;
14
use React\EventLoop\LoopInterface;
15
use function Composed\package;
16
17
final class Factory
18
{
19
    const DEFAULT_OPTIONS = [
20
        'extra_expires' => [
21
            'text/plain' => '+1 year',
22
        ],
23
        'proxy' => [
24
            '127.0.0.1',
25
        ],
26
        'access_log_format' => '%a %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"',
27
    ];
28
29 1
    public static function create(LoopInterface $loop, LoggerInterface $logger, array $options = []): GroupedPSR15Middleware
30
    {
31 1
        $options = array_merge(self::DEFAULT_OPTIONS, $options);
32 1
        $expires = require package('middlewares/cache')->getPath('src/expires_defaults.php');
33 1
        foreach ($options['extra_expires'] as $key => $value) {
34 1
            $expires[$key] = $value;
35
        }
36
37 1
        return (new GroupedPSR15Middleware($loop))->
38 1
            withMiddleware(ClientIp::class, [], function ($clientIp) use ($options) {
39 1
                if (count($options['proxy']) > 0) {
40 1
                    return $clientIp->proxy($options['proxy']);
41
                }
42
43
                return $clientIp;
44 1
            })->
45 1
            withMiddleware(Uuid::class)->
46 1
            withMiddleware(AccessLog::class, [$logger], function ($accessLog) use ($options) {
47
                return $accessLog->
48 1
                    format($options['access_log_format'])->
49 1
                    ipAttribute('client-ip')->
50 1
                    context(function (ServerRequestInterface $request, ResponseInterface $response) {
51
                        return [
52
                            'client-ip' => $request->getAttribute('client-ip'),
53
                            'request-id' => $request->getHeaderLine('X-Uuid'),
54
                            'request-method' => $request->getMethod(),
55
                            'request-protocol-version' => $request->getProtocolVersion(),
56
                            'response-protocol-version' => $response->getProtocolVersion(),
57
                            'response-status-code' => $response->getStatusCode(),
58
                            'response-time' => $response->getHeaderLine('X-Response-Time'),
59
                            'response-time-float' => substr($response->getHeaderLine('X-Response-Time'), 0, -2),
60
                            'response-time-float-single-digit' => round((float)substr($response->getHeaderLine('X-Response-Time'), 0, -2), 1),
61
                            'response-time-int' => (int)round((float)substr($response->getHeaderLine('X-Response-Time'), 0, -2), 0),
62
                        ];
63 1
                    })
64
                ;
65 1
            })->
66 1
            withMiddleware(ResponseTime::class)->
67 1
            withMiddleware(Expires::class, [$expires]);
68
    }
69
}
70