SignRequestMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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