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.
Test Failed
Pull Request — master (#54)
by Yong
04:48
created

UserAgent   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Test Coverage

Coverage 94.29%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 105
ccs 33
cts 35
cp 0.9429
rs 10
c 0
b 0
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isGuarded() 0 3 1
A append() 0 6 2
A toString() 0 22 3
A clear() 0 3 1
A with() 0 4 2
A defaultFields() 0 10 3
1
<?php
2
3
namespace AlibabaCloud\Client\Request;
4
5
use AlibabaCloud\Client\AlibabaCloud;
6
use GuzzleHttp\Client;
7
8
/**
9
 * Class UserAgent
10
 *
11
 * @package AlibabaCloud\Client\Request
12
 */
13
class UserAgent
14
{
15
16
    /**
17
     * @var array
18
     */
19
    private static $userAgent = [];
20
21
    /**
22
     * @var array
23
     */
24
    private static $guard = [
25
        'client',
26
        'guzzlehttp',
27
        'curl',
28
        'php',
29
    ];
30
31
    /**
32
     * UserAgent constructor.
33
     */
34
    private static function defaultFields()
35 70
    {
36
        if (self::$userAgent === []) {
37 70
            self::$userAgent = [
38
                'Client'     => AlibabaCloud::VERSION,
39 70
                'GuzzleHttp' => Client::VERSION,
40 70
                'curl'       => isset(\curl_version()['version'])
41 70
                    ? \curl_version()['version']
42 70
                    : 'none',
43
                'PHP'        => \PHP_VERSION,
44 70
            ];
45 70
        }
46 70
    }
47
48
    /**
49
     * @param array $append
50 70
     *
51 70
     * @return string
52 70
     */
53
    public static function toString(array $append = [])
54
    {
55
        self::defaultFields();
56
57
        $os         = \PHP_OS;
58
        $os_version = php_uname('r');
59
        $os_mode    = php_uname('m');
60
        $userAgent  = "AlibabaCloud ($os $os_version; $os_mode) ";
61 3
62
        $newUserAgent = [];
63 3
64
        $append = array_merge(self::$userAgent, $append);
65 3
66 2
        foreach ($append as $key => $value) {
67 2
            if ($value === null) {
68 3
                $newUserAgent[] = $key;
69
                continue;
70
            }
71
            $newUserAgent[] = "$key/$value";
72
        }
73 70
74
        return $userAgent . \implode(' ', $newUserAgent);
75 70
    }
76 1
77 1
    /**
78 1
     * set User Agent of Alibaba Cloud.
79 1
     *
80 1
     * @param string $name
81 1
     * @param string $value
82 1
     */
83 1
    public static function append($name, $value)
84 1
    {
85 1
        self::defaultFields();
86 70
87
        if (!self::isGuarded($name)) {
88
            self::$userAgent[$name] = $value;
89
        }
90
    }
91
92
    /**
93 3
     * @param array $userAgent
94
     */
95 3
    public static function with(array $userAgent)
96
    {
97
        foreach ($userAgent as $key => $value) {
98
            self::append($key, $value);
99
        }
100
    }
101
102
    /**
103
     * Clear all of the User Agent.
104
     */
105
    public static function clear()
106
    {
107
        self::$userAgent = [];
108
    }
109
110
    /**
111
     * @param $name
112
     *
113
     * @return bool
114
     */
115
    public static function isGuarded($name)
116
    {
117
        return in_array(strtolower($name), self::$guard, true);
118
    }
119
}
120