ApiKeyCredentials   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 35
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHash() 0 3 1
A getSecretKey() 0 3 1
A getAccessKey() 0 3 1
A provide() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\DigiSign\Auth;
6
7
use DigitalCz\DigiSign\DigiSign;
8
9
/**
10
 * Credentials that are fetched with accessKey/secretKey
11
 */
12
final class ApiKeyCredentials implements Credentials
13
{
14
    /** @var string  */
15
    private $accessKey;
16
17
    /** @var string  */
18
    private $secretKey;
19
20
    public function __construct(string $accessKey, string $secretKey)
21
    {
22
        $this->accessKey = $accessKey;
23
        $this->secretKey = $secretKey;
24
    }
25
26
    public function getAccessKey(): string
27
    {
28
        return $this->accessKey;
29
    }
30
31
    public function getSecretKey(): string
32
    {
33
        return $this->secretKey;
34
    }
35
36
    public function getHash(): string
37
    {
38
        return md5($this->accessKey . $this->secretKey);
39
    }
40
41
    public function provide(DigiSign $dgs): Token
42
    {
43
        $body = ['accessKey' => $this->getAccessKey(), 'secretKey' => $this->getSecretKey()];
44
        $token = $dgs->auth()->authorize($body);
45
46
        return new Token($token->token, $token->exp);
47
    }
48
}
49