Total Complexity | 4 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Authentication |
||
11 | { |
||
12 | /** @var string */ |
||
13 | private $key; |
||
14 | |||
15 | /** @var string */ |
||
16 | private $secret; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $nonce; |
||
20 | |||
21 | /** |
||
22 | * Authentication constructor. |
||
23 | * @param string $key |
||
24 | * @param string $secret |
||
25 | * @param string $nonce |
||
26 | */ |
||
27 | 17 | public function __construct(string $key, string $secret, string $nonce) |
|
28 | { |
||
29 | 17 | $this->key = $key; |
|
30 | 17 | $this->secret = $secret; |
|
31 | 17 | $this->nonce = $nonce; |
|
32 | 17 | } |
|
33 | |||
34 | /** |
||
35 | * @param callable $next |
||
36 | * @return Closure |
||
37 | */ |
||
38 | 15 | public function __invoke(callable $next) |
|
39 | { |
||
40 | return function (RequestInterface $request, array $options = []) use ($next) { |
||
41 | |||
42 | 15 | $request = $this->addAuthQueryParams($request); |
|
43 | 15 | $sign = $this->generateSign($request->getUri()->__toString()); |
|
44 | 15 | $request = $request->withAddedHeader('apisign', $sign); |
|
45 | |||
46 | 15 | return $next($request, $options); |
|
47 | 15 | }; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param RequestInterface $request |
||
52 | * @return RequestInterface |
||
53 | */ |
||
54 | 15 | private function addAuthQueryParams(RequestInterface $request): RequestInterface |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $uri |
||
66 | * @return string |
||
67 | */ |
||
68 | 15 | private function generateSign(string $uri): string |
|
71 | } |
||
72 | } |
||
73 |