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

SignRequestMiddleware::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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