Conditions | 3 |
Paths | 1 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
38 | 19 | public function __invoke(callable $next) |
|
39 | { |
||
40 | 19 | return function (RequestInterface $request, array $options = []) use ($next) { |
|
41 | 19 | $timestamp = round(microtime(true) * 1000); |
|
42 | 19 | $contentHash = $this->generateContentHash($request->getBody()->__toString()); |
|
43 | $pre_sign = $timestamp . |
||
44 | 19 | $request->getUri()->__toString() . |
|
45 | 19 | $request->getMethod() . |
|
46 | 19 | $contentHash . |
|
47 | 19 | $this->subaccountId; |
|
48 | 19 | $sign = $this->generateSign($pre_sign); |
|
49 | $newHeaders = [ |
||
50 | 19 | 'Api-Key' => $this->key, |
|
51 | 19 | 'Api-Timestamp' => $timestamp, |
|
52 | 19 | 'Api-Content-Hash' => $contentHash, |
|
53 | 19 | 'Api-Signature' => $sign |
|
54 | ]; |
||
55 | 19 | foreach ($newHeaders as $key => $value) $request = $request->withAddedHeader($key, $value); |
|
56 | 19 | if (!is_null($this->subaccountId)) $request = $request->withAddedHeader('Api-Subaccount-Id', $this->subaccountId); |
|
57 | |||
58 | 19 | return $next($request, $options); |
|
59 | 19 | }; |
|
60 | } |
||
61 | |||
80 | } |