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 ( 8b388c...a617ff )
by Cees-Jan
01:27
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 76%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 48
ccs 19
cts 25
cp 0.76
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 35 3
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
                        '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
                        'response-status-code' => $response->getStatusCode(),
57
                    ];
58 1
                })
59
                ;
60 1
            })->
61 1
            withMiddleware(ResponseTime::class)->
62 1
            withMiddleware(Expires::class, [$expires]);
63
    }
64
}
65