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.
Passed
Pull Request — master (#71)
by Yong
10:54 queued 05:16
created

ManageTrait::asDefaultClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Clients;
4
5
use AlibabaCloud\Client\AlibabaCloud;
6
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
7
use AlibabaCloud\Client\Credentials\CredentialsInterface;
8
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
9
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
10
use AlibabaCloud\Client\Credentials\Providers\EcsRamRoleProvider;
11
use AlibabaCloud\Client\Credentials\Providers\RamRoleArnProvider;
12
use AlibabaCloud\Client\Credentials\Providers\RsaKeyPairProvider;
13
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
14
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential;
15
use AlibabaCloud\Client\Credentials\StsCredential;
16
use AlibabaCloud\Client\Exception\ClientException;
17
use AlibabaCloud\Client\Exception\ServerException;
18
19
/**
20
 * Trait ManageTrait.
21
 *
22
 * @mixin     Client
23
 */
24
trait ManageTrait
25
{
26
    /**
27
     * @param int $timeout
28
     *
29
     * @return AccessKeyCredential|CredentialsInterface|StsCredential
30
     *
31
     * @throws ClientException
32
     * @throws ServerException
33
     */
34 75
    public function getSessionCredential($timeout = \ALIBABA_CLOUD_TIMEOUT)
35
    {
36 75
        switch (\get_class($this->credential)) {
37 75
            case EcsRamRoleCredential::class:
38 9
                return (new EcsRamRoleProvider($this))->get();
39 66
            case RamRoleArnCredential::class:
40 7
                return (new RamRoleArnProvider($this))->get($timeout);
41 59
            case RsaKeyPairCredential::class:
42 8
                return (new RsaKeyPairProvider($this))->get($timeout);
43 51
            default:
44 51
                return $this->credential;
45 51
        }
46
    }
47
48
    /**
49
     * Naming clients.
50
     *
51
     * @param string $name
52
     *
53
     * @return static
54
     * @throws ClientException
55
     */
56 129
    public function name($name)
57
    {
58 129
        if (!$name) {
59 1
            throw new ClientException(
60 1
                'The argument $name cannot be empty',
61
                \ALIBABA_CLOUD_INVALID_ARGUMENT
62 1
            );
63
        }
64
65 128
        return AlibabaCloud::set($name, $this);
66
    }
67
68
    /**
69
     * @deprecated
70
     * @codeCoverageIgnore
71
     * Set the current client as the global client.
72
     *
73
     * @return static
74
     * @throws ClientException
75
     */
76
    public function asGlobalClient()
77
    {
78
        return $this->asDefaultClient();
79
    }
80
81
    /**
82
     * Set the current client as the default client.
83
     *
84
     * @return static
85
     * @throws ClientException
86
     */
87 38
    public function asDefaultClient()
88
    {
89 38
        return $this->name(CredentialsProvider::getDefaultName());
90
    }
91
92
    /**
93
     * @return bool
94
     */
95 30
    public function isDebug()
96
    {
97 30
        if (isset($this->options['debug'])) {
98 2
            return true === $this->options['debug'] && PHP_SAPI === 'cli';
99
        }
100
101 29
        return false;
102
    }
103
}
104