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 ( fdb90a...d17bc9 )
by herry
03:35
created

Sign::_createLinkString()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 4
eloc 6
c 2
b 2
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
4
namespace MuCTS\Laravel\GuiJK;
5
6
7
use Illuminate\Support\Arr;
8
9
trait Sign
10
{
11
    /**
12
     * 校验签名
13
     *
14
     * @param array $param
15
     * @param string $secretKey
16
     * @return bool
17
     */
18
    public function verifySign(array $param, string $secretKey)
19
    {
20
        return $this->generateSign($param, $secretKey) === Arr::get($param, 'sign');
21
    }
22
23
    /**
24
     * 签名
25
     *
26
     * @param array $param
27
     * @param string $secretKey
28
     * @return string
29
     * @author herry.yao<[email protected]>
30
     */
31
    public function generateSign(array $param, string $secretKey)
32
    {
33
        $this->_dictSort($param);
34
        return strtoupper(md5($this->_createLinkString($param) . '&key=' . $secretKey));
35
    }
36
37
    /**
38
     * 字典排序
39
     *
40
     * @param array $param 待排序参数
41
     */
42
    private function _dictSort(array &$param)
43
    {
44
        ksort($param);
45
        reset($param);
46
    }
47
48
    /**
49
     * 字符串拼接并去除转义
50
     * @param array $param 带拼接数组
51
     * @return string
52
     */
53
    private function _createLinkString(array $param = [])
54
    {
55
        return collect($param)->filter(function ($value, $key) {
56
            return !is_null($value) && $value !== '' && !Arr::exists(['sign', 'sign_type'], $key);
57
        })->map(function ($value, $key) {
58
            return sprintf('%s=%s', $key,
59
                is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value);
60
        })->implode('&');
61
    }
62
}