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.

TemplateRenderMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use React\Promise\PromiseInterface;
8
use function React\Promise\resolve;
9
use function RingCentral\Psr7\stream_for;
10
use Twig\Environment;
11
12
/**
13
 * @internal
14
 */
15
final class TemplateRenderMiddleware
16
{
17
    /** @var Environment */
18
    private $twig;
19
20
    /**
21
     * @param Environment $twig
22
     */
23
    public function __construct(Environment $twig)
24
    {
25
        $this->twig = $twig;
26
    }
27
28
    public function __invoke(ServerRequestInterface $request, callable $next): PromiseInterface
29
    {
30
        return resolve($next($request))->then(function (ResponseInterface $response) {
31
            if ($response instanceof TemplateResponse) {
32
                $response = $response->withBody(
33
                    stream_for(
34
                        $this->twig->render(
35
                            $response->getTemplate(),
36
                            $response->getTemplateData()
37
                        )
38
                    )
39
                );
40
            }
41
42
            return $response;
43
        });
44
    }
45
}
46