SignRequestMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 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\SigningSecretKey;
8
use ParagonIE\Sapient\Sapient;
9
use Psr\Http\Message\RequestInterface;
10
11
class SignRequestMiddleware
12
{
13
    /**
14
     * @var Sapient
15
     */
16
    private $sapient;
17
18
    /**
19
     * @var string
20
     */
21
    private $signPrivateKey;
22
23
    /**
24
     * @param Sapient $sapient
25
     * @param string $signPrivateKey
26
     */
27 2
    public function __construct(Sapient $sapient, string $signPrivateKey)
28
    {
29 2
        $this->sapient = $sapient;
30 2
        $this->signPrivateKey = $signPrivateKey;
31 2
    }
32
33 2
    public function __invoke(callable $handler): callable
34
    {
35
        return function(RequestInterface $request, array $options) use ($handler) {
36 2
            return $handler(
37 2
                $this->sapient->signRequest($request, new SigningSecretKey(Base64UrlSafe::decode($this->signPrivateKey))),
38 2
                $options
39
            );
40 2
        };
41
    }
42
}
43