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.

Sign::resourceString()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace AlibabaCloud\Client\Support;
4
5
use GuzzleHttp\Psr7\Request;
6
use Psr\Http\Message\UriInterface;
7
8
/**
9
 * Class Sign
10
 *
11
 * @package AlibabaCloud\Client\Support
12
 */
13
class Sign
14
{
15
    /**
16
     * @var string
17
     */
18
    private static $headerSeparator = "\n";
19
20
    /**
21
     * Construct standard Header for Alibaba Cloud.
22
     *
23
     * @param array $headers
24
     *
25
     * @return string
26
     */
27 18
    private static function acsHeaderString(array $headers)
28
    {
29 18
        $array = [];
30 18
        foreach ($headers as $headerKey => $headerValue) {
31 18
            $key = strtolower($headerKey);
32 18
            if (strncmp($key, 'x-acs-', 6) === 0) {
33 18
                $array[$key] = $headerValue;
34 18
            }
35 18
        }
36 18
        ksort($array);
37 18
        $string = '';
38 18
        foreach ($array as $sortMapKey => $sortMapValue) {
39 18
            $string .= $sortMapKey . ':' . $sortMapValue[0] . self::$headerSeparator;
40 18
        }
41
42 18
        return $string;
43
    }
44
45
    /**
46
     * @param UriInterface $uri
47
     *
48
     * @return string
49
     */
50 18
    private static function resourceString(UriInterface $uri)
51
    {
52 18
        return $uri->getPath() . '?' . rawurldecode($uri->getQuery());
53
    }
54
55
    /**
56
     * @param string $method
57
     * @param array  $headers
58
     *
59
     * @return string
60
     */
61 18
    private static function headerString($method, array $headers)
62
    {
63 18
        $string = $method . self::$headerSeparator;
64 18
        if (isset($headers['Accept'][0])) {
65 18
            $string .= $headers['Accept'][0];
66 18
        }
67 18
        $string .= self::$headerSeparator;
68
69 18
        if (isset($headers['Content-MD5'][0])) {
70 3
            $string .= $headers['Content-MD5'][0];
71 3
        }
72 18
        $string .= self::$headerSeparator;
73
74 18
        if (isset($headers['Content-Type'][0])) {
75 18
            $string .= $headers['Content-Type'][0];
76 18
        }
77 18
        $string .= self::$headerSeparator;
78
79 18
        if (isset($headers['Date'][0])) {
80 18
            $string .= $headers['Date'][0];
81 18
        }
82 18
        $string .= self::$headerSeparator;
83
84 18
        $string .= self::acsHeaderString($headers);
85
86 18
        return $string;
87
    }
88
89
    /**
90
     * @param string $string
91
     *
92
     * @return null|string|string[]
93
     */
94 66
    private static function percentEncode($string)
95
    {
96 66
        $result = urlencode($string);
97 66
        $result = str_replace(['+', '*'], ['%20', '%2A'], $result);
98 66
        $result = preg_replace('/%7E/', '~', $result);
99
100 66
        return $result;
101
    }
102
103
    /**
104
     * @param string $method
105
     * @param array  $parameters
106
     *
107
     * @return string
108
     */
109 63
    public static function rpcString($method, array $parameters)
110
    {
111 63
        ksort($parameters);
112 63
        $canonicalized = '';
113 63
        foreach ($parameters as $key => $value) {
114 63
            if ($value === null || $value === '') {
115 63
                continue;
116
            }
117 63
            $canonicalized .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value);
118
        }
119
120
        return $method . '&%2F&' . self::percentEncode(substr($canonicalized, 1));
121
    }
122
123
    /**
124
     * @param Request $request
125 18
     *
126
     * @return string
127 18
     */
128 18
    public static function roaString(Request $request)
129
    {
130
        return self::headerString($request->getMethod(), $request->getHeaders()) .
131
               self::resourceString($request->getUri());
132
    }
133
134
    /**
135
     * @param string $salt
136 82
     *
137
     * @return string
138 82
     */
139
    public static function uuid($salt)
140
    {
141
        return md5($salt . uniqid(md5(microtime(true)), true)) . microtime();
142
    }
143
}
144