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
Push — master ( f27185...67f805 )
by Yong
05:10
created

UserAgent::isGuarded()   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 1
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\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
        'php',
26
        'client',
27
        'zend',
28
        'guzzle',
29
        'curl',
30
    ];
31
32
    /**
33
     * @return string
34
     */
35 70
    public static function toString()
36
    {
37 70
        self::defaultFields();
38
39 70
        $os         = \PHP_OS;
40 70
        $os_version = php_uname('r');
41 70
        $os_mode    = php_uname('m');
42 70
        $userAgent  = "AlibabaCloud ($os $os_version; $os_mode) ";
43
44 70
        $newUserAgent = [];
45 70
        foreach (self::$userAgent as $key => $value) {
46 70
            if ($value === null) {
47
                $newUserAgent[] = $key;
48
                continue;
49
            }
50 70
            $newUserAgent[] = $key . '/' . $value;
51 70
        }
52 70
        return $userAgent . \implode(' ', $newUserAgent);
53
    }
54
55
    /**
56
     * set User Agent of Alibaba Cloud.
57
     *
58
     * @param string $name
59
     * @param string $value
60
     */
61 3
    public static function append($name, $value)
62
    {
63 3
        self::defaultFields();
64
65 3
        if (!self::isGuarded($name)) {
66 2
            self::$userAgent[$name] = $value;
67 2
        }
68 3
    }
69
70
    /**
71
     * UserAgent constructor.
72
     */
73 70
    private static function defaultFields()
74
    {
75 70
        if (self::$userAgent === []) {
76 1
            self::$userAgent = [
77 1
                'PHP'    => \PHP_VERSION,
78 1
                'Client' => AlibabaCloud::VERSION,
79 1
                'Zend'   => zend_version(),
80 1
                'Guzzle' => Client::VERSION,
81 1
                'CURL'   => isset(\curl_version()['version'])
82 1
                    ? \curl_version()['version']
83 1
                    : 'none',
84 1
            ];
85 1
        }
86 70
    }
87
88
    /**
89
     * @param $name
90
     *
91
     * @return bool
92
     */
93 3
    private static function isGuarded($name)
94
    {
95 3
        return in_array(strtolower($name), self::$guard, true);
96
    }
97
}
98