Passed
Push — main ( 839b76...3b8d69 )
by Stas
05:20
created

AuthorizationStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 5 1
A fetch() 0 5 1
A transformCredentialsToKey() 0 3 1
1
<?php
2
3
namespace Huawei\IAP;
4
5
/**
6
 * Class AuthorizationStorage
7
 * @package Huawei\IAP
8
 */
9
class AuthorizationStorage
10
{
11
    protected $data;
12
13
    /**
14
     * @param AuthorizationCredentials $credentials
15
     *
16
     * @return string|null
17
     */
18 1
    protected function transformCredentialsToKey(AuthorizationCredentials $credentials): ?string
19
    {
20 1
        return sprintf('%s_%s', $credentials->getApplicationId(), $credentials->getAppKey());
21
    }
22
23
    /**
24
     * @param AuthorizationCredentials $credentials
25
     *
26
     * @return string|null
27
     */
28 1
    public function fetch(AuthorizationCredentials $credentials): ?string
29
    {
30 1
        $key = $this->transformCredentialsToKey($credentials);
31
32 1
        return $this->data[$key] ?? null;
33
    }
34
35
    /**
36
     * @param AuthorizationCredentials $credentials
37
     * @param string                   $accessToken
38
     */
39 1
    public function save(AuthorizationCredentials $credentials, string $accessToken): void
40
    {
41 1
        $key = $this->transformCredentialsToKey($credentials);
42
43 1
        $this->data[$key] = $accessToken;
44 1
    }
45
}
46