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 ( 83def8...1f1fc7 )
by Cees-Jan
01:56
created

Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 61
ccs 21
cts 35
cp 0.6
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 48 5
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\Https;
10
use Middlewares\ResponseTime;
11
use Middlewares\Uuid;
12
use Psr\Http\Message\ResponseInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
use Psr\Log\LoggerInterface;
15
use React\EventLoop\LoopInterface;
16
use function Composed\package;
17
18
final class Factory
19
{
20
    const DEFAULT_OPTIONS = [
21
        'extra_expires' => [
22
            'text/plain' => '+1 year',
23
        ],
24
        'proxy' => [
25
            '127.0.0.1',
26
        ],
27
        'access_log_format' => '%a %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"',
28
    ];
29
30 1
    public static function create(LoopInterface $loop, LoggerInterface $logger, array $options = []): GroupedPSR15Middleware
31
    {
32 1
        $options = array_merge(self::DEFAULT_OPTIONS, $options);
33 1
        $expires = require package('middlewares/cache')->getPath('src/expires_defaults.php');
34 1
        foreach ($options['extra_expires'] as $key => $value) {
35 1
            $expires[$key] = $value;
36
        }
37
38 1
        $middleware = (new GroupedPSR15Middleware($loop))->
39 1
            withMiddleware(ClientIp::class, [], function ($clientIp) use ($options) {
40 1
                if (count($options['proxy']) > 0) {
41 1
                    return $clientIp->proxy($options['proxy']);
42
                }
43
44
                return $clientIp;
45 1
            })->
46 1
            withMiddleware(Uuid::class)->
47 1
            withMiddleware(AccessLog::class, [$logger], function ($accessLog) use ($options) {
48
                return $accessLog->
49 1
                    format($options['access_log_format'])->
50 1
                    ipAttribute('client-ip')->
51 1
                    context(function (ServerRequestInterface $request, ResponseInterface $response) {
52
                        return [
53
                            'client-ip' => $request->getAttribute('client-ip'),
54
                            'request-id' => $request->getHeaderLine('X-Uuid'),
55
                            'request-method' => $request->getMethod(),
56
                            'request-protocol-version' => $request->getProtocolVersion(),
57
                            'response-protocol-version' => $response->getProtocolVersion(),
58
                            'response-status-code' => $response->getStatusCode(),
59
                            'response-time' => $response->getHeaderLine('X-Response-Time'),
60
                            'response-time-float' => substr($response->getHeaderLine('X-Response-Time'), 0, -2),
61
                            'response-time-float-single-digit' => round((float)substr($response->getHeaderLine('X-Response-Time'), 0, -2), 1),
62
                            'response-time-int' => (int)round((float)substr($response->getHeaderLine('X-Response-Time'), 0, -2), 0),
63
                        ];
64 1
                    })
65
                ;
66 1
            })->
67 1
            withMiddleware(ResponseTime::class)->
68 1
            withMiddleware(Expires::class, [$expires]);
69
70 1
        if (isset($options['hsts']) && $options['hsts'] === true) {
71
            $middleware = $middleware->withMiddleware(Https::class, [], function ($https) {
72
                return $https->redirect(false);
73
            });
74
        }
75
76 1
        return $middleware;
77
    }
78
}
79