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.

Signature::SignRequest()   B
last analyzed

Complexity

Conditions 7
Paths 48

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 35
CRAP Score 7.0077

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 43
ccs 35
cts 37
cp 0.9459
c 0
b 0
f 0
rs 8.5386
cc 7
nc 48
nop 2
crap 7.0077
1
<?php
2
3
/** @noinspection PhpMissingDocCommentInspection */
4
5
namespace AlibabaCloud\Dybaseapi\MNS;
6
7
use AlibabaCloud\Dybaseapi\MNS\Requests\BaseRequest;
8
9
/**
10
 * Class Signature
11
 *
12
 * @package AlibabaCloud\Dybaseapi\MNS
13
 */
14
class Signature
15
{
16
    const MNS_HEADER_PREFIX = 'x-mns';
17
18
    /**
19
     * @param string      $accessKey
20
     * @param BaseRequest $request
21
     *
22
     * @return string
23
     */
24 1
    public static function SignRequest($accessKey, BaseRequest $request)
25
    {
26 1
        $headers    = $request->getHeaders();
27 1
        $contentMd5 = '';
28 1
        if (isset($headers['Content-MD5'])) {
29
            $contentMd5 = $headers['Content-MD5'];
30
        }
31 1
        $contentType = '';
32 1
        if (isset($headers['Content-Type'])) {
33 1
            $contentType = $headers['Content-Type'];
34 1
        }
35 1
        $date                  = $headers['Date'];
36 1
        $queryString           = $request->getQueryString();
37 1
        $canonicalizedResource = $request->getResourcePath();
38 1
        if ($queryString !== null) {
0 ignored issues
show
introduced by
The condition $queryString !== null is always true.
Loading history...
39 1
            $canonicalizedResource .= '?' . $request->getQueryString();
40 1
        }
41 1
        if (0 !== strpos($canonicalizedResource, '/')) {
42 1
            $canonicalizedResource = '/' . $canonicalizedResource;
43 1
        }
44
45 1
        $tmpHeaders = [];
46 1
        foreach ($headers as $key => $value) {
47 1
            if (0 === strpos($key, Constants::MNS_HEADER_PREFIX)) {
48 1
                $tmpHeaders[$key] = $value;
49 1
            }
50 1
        }
51
52 1
        $canonicalizedMNSHeaders = implode(
53 1
            "\n",
54 1
            array_map(
55 1
                static function ($v, $k) {
56 1
                    return $k . ':' . $v;
57 1
                },
58 1
                $tmpHeaders,
59 1
                array_keys($tmpHeaders)
60 1
            )
61 1
        );
62
63
        $stringToSign =
64 1
            strtoupper($request->getMethod()) . "\n" . $contentMd5 . "\n" . $contentType . "\n" . $date . "\n" . $canonicalizedMNSHeaders . "\n" . $canonicalizedResource;
65
66 1
        return base64_encode(hash_hmac('sha1', $stringToSign, $accessKey, $raw_output = true));
67
    }
68
}
69