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::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 8
rs 10
ccs 5
cts 5
cp 1
crap 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