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 ( 43287f...6fcc85 )
by Cees-Jan
01:27
created

Factory::construct()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3.0813

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 19
cts 24
cp 0.7917
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 25
nc 2
nop 3
crap 3.0813
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 construct(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
                        'request-id' => $request->getHeaderLine('X-Uuid'),
53
                        'response-time' => $response->getHeaderLine('X-Response-Time'),
54
                        'response-time-float' => substr($response->getHeaderLine('X-Response-Time'), 0, -2),
55
                        'client-ip' => $request->getAttribute('client-ip'),
56
                    ];
57 1
                })
58
                ;
59 1
            })->
60 1
            withMiddleware(ResponseTime::class)->
61 1
            withMiddleware(Expires::class, [$expires]);
62
    }
63
}
64