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.

WithHeadersMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 18
rs 10
ccs 8
cts 8
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\React\Http\Middleware;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use React\Promise\PromiseInterface;
10
11
use function React\Promise\resolve;
12
13
final class WithHeadersMiddleware
14
{
15
    /** @var Header[] */
16 1
    private array $headers;
17
18 1
    public function __construct(Header ...$headers)
19 1
    {
20
        $this->headers = $headers;
21
    }
22
23 1
    public function __invoke(ServerRequestInterface $request, callable $next): PromiseInterface
24 1
    {
25 1
        return resolve($next($request))->then(function (ResponseInterface $response): ResponseInterface {
26
            foreach ($this->headers as $header) {
27
                $response = $response->withHeader($header->name(), $header->contents());
28 1
            }
29 1
30
            return $response;
31
        });
32
    }
33
}
34