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
03:58
created

UserAgent::with()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
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
        foreach ($append as $key => $value) {
65 3
            if (isset(self::$userAgent[$key])) {
66 2
                unset($append[$key]);
67 2
            }
68 3
        }
69
70
        $append = array_merge(self::$userAgent, $append);
71
72
        foreach ($append as $key => $value) {
73 70
            if ($value === null) {
74
                $newUserAgent[] = $key;
75 70
                continue;
76 1
            }
77 1
            $newUserAgent[] = "$key/$value";
78 1
        }
79 1
80 1
        return $userAgent . \implode(' ', $newUserAgent);
81 1
    }
82 1
83 1
    /**
84 1
     * set User Agent of Alibaba Cloud.
85 1
     *
86 70
     * @param string $name
87
     * @param string $value
88
     */
89
    public static function append($name, $value)
90
    {
91
        self::defaultFields();
92
93 3
        if (!self::isGuarded($name)) {
94
            self::$userAgent[$name] = $value;
95 3
        }
96
    }
97
98
    /**
99
     * @param array $userAgent
100
     */
101
    public static function with(array $userAgent)
102
    {
103
        foreach ($userAgent as $key => $value) {
104
            self::append($key, $value);
105
        }
106
    }
107
108
    /**
109
     * Clear all of the User Agent.
110
     */
111
    public static function clear()
112
    {
113
        self::$userAgent = [];
114
    }
115
116
    /**
117
     * @param $name
118
     *
119
     * @return bool
120
     */
121
    public static function isGuarded($name)
122
    {
123
        return in_array(strtolower($name), self::$guard, true);
124
    }
125
}
126