UnsealResponseMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace lepiaf\SapientBundle\GuzzleHttp\Middleware;
5
6
use ParagonIE\ConstantTime\Base64UrlSafe;
7
use ParagonIE\Sapient\CryptographyKeys\SealingSecretKey;
8
use ParagonIE\Sapient\Sapient;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
class UnsealResponseMiddleware
13
{
14
    /**
15
     * @var Sapient
16
     */
17
    private $sapient;
18
19
    /**
20
     * @var string
21
     */
22
    private $privateKey;
23
24 2
    public function __construct(Sapient $sapient, string $privateKey)
25
    {
26 2
        $this->sapient = $sapient;
27 2
        $this->privateKey = $privateKey;
28 2
    }
29
30 2
    public function __invoke(callable $handler)
31
    {
32
        return function(RequestInterface $request, array $options) use ($handler) {
33 2
            return $handler($request, $options)->then(
34
                function(ResponseInterface $response) {
35 2
                    $responseUnsealed = $this->sapient->unsealResponse(
36 2
                        $response,
37 2
                        new SealingSecretKey(Base64UrlSafe::decode($this->privateKey))
38
                    );
39
40 1
                    return $responseUnsealed;
41 2
                }
42
            );
43 2
        };
44
    }
45
}
46