Passed
Pull Request — master (#19)
by Thierry
02:48
created

SignRequestMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 1
A __construct() 0 4 1
1
<?php
2
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
    private $sapient;
14
    private $privateKey;
15
16
    public function __construct(Sapient $sapient, string $privateKey)
17
    {
18
        $this->sapient = $sapient;
19
        $this->privateKey = $privateKey;
20
    }
21
22
    public function __invoke(callable $handler)
23
    {
24
        return function (RequestInterface $request, array $options) use ($handler) {
25
            $request = $this->sapient->signRequest(
26
                $request,
27
                new SigningSecretKey(Base64UrlSafe::decode($this->privateKey))
28
            );
29
30
            return $handler($request, $options);
31
        };
32
    }
33
}
34