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

AuthorizationStorage::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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