GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Provider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 75
ccs 15
cts 15
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A cache() 0 3 1
A key() 0 3 1
A getCredentialsInCache() 0 11 3
A __construct() 0 3 1
1
<?php
2
3
namespace AlibabaCloud\Client\Credentials\Providers;
4
5
use AlibabaCloud\Client\Clients\Client;
6
7
/**
8
 * Class Provider
9
 *
10
 * @package   AlibabaCloud\Client\Credentials\Providers
11
 */
12
class Provider
13
{
14
    /**
15
     * For TSC Duration Seconds
16
     */
17
    const DURATION_SECONDS = 3600;
18
19
    /**
20
     * @var array
21
     */
22
    protected static $credentialsCache = [];
23
24
    /**
25
     * Expiration time slot for temporary security credentials.
26
     *
27
     * @var int
28
     */
29
    protected $expirationSlot = 180;
30
31
    /**
32
     * @var Client
33
     */
34
    protected $client;
35
36
    /**
37
     * @var string
38
     */
39
    protected $error = 'Result contains no credentials';
40
41
    /**
42
     * CredentialTrait constructor.
43
     *
44
     * @param Client $client
45
     */
46 47
    public function __construct(Client $client)
47
    {
48 47
        $this->client = $client;
49 47
    }
50
51
    /**
52
     * Get the credentials from the cache in the validity period.
53
     *
54
     * @return array|null
55
     */
56 33
    public function getCredentialsInCache()
57
    {
58 33
        if (isset(self::$credentialsCache[$this->key()])) {
59 13
            $result = self::$credentialsCache[$this->key()];
60 13
            if (\strtotime($result['Expiration']) - \time() >= $this->expirationSlot) {
61 6
                return $result;
62
            }
63 7
            unset(self::$credentialsCache[$this->key()]);
64 7
        }
65
66 27
        return null;
67
    }
68
69
    /**
70
     * Get the toString of the credentials as the key.
71
     *
72
     * @return string
73
     */
74 47
    protected function key()
75
    {
76 47
        return (string)$this->client->getCredential();
77
    }
78
79
    /**
80
     * Cache credentials.
81
     *
82
     * @param array $credential
83
     */
84 22
    protected function cache(array $credential)
85
    {
86 22
        self::$credentialsCache[$this->key()] = $credential;
87 22
    }
88
}
89