CookieSendMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HttpSoft\Cookie;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
12
final class CookieSendMiddleware implements MiddlewareInterface
13
{
14
    /**
15
     * @var CookieManagerInterface
16
     */
17
    private CookieManagerInterface $cookies;
18
19
    /**
20
     * @var bool
21
     */
22
    private bool $removeResponseCookies;
23
24
    /**
25
     * @param CookieManagerInterface $cookies object with cookies to set in response.
26
     * @param bool $removeResponseCookies whether to remove previously set cookies from the response.
27
     */
28 6
    public function __construct(CookieManagerInterface $cookies, bool $removeResponseCookies = true)
29
    {
30 6
        $this->cookies = $cookies;
31 6
        $this->removeResponseCookies = $removeResponseCookies;
32
    }
33
34
    /**
35
     * @param ServerRequestInterface $request
36
     * @param RequestHandlerInterface $handler
37
     * @return ResponseInterface
38
     */
39 6
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
40
    {
41 6
        $response = $handler->handle($request);
42 6
        return $this->cookies->send($response, $this->removeResponseCookies);
43
    }
44
}
45