Tools::verifySignature()   B
last analyzed

Complexity

Conditions 8
Paths 3

Size

Total Lines 21
Code Lines 14

Duplication

Lines 3
Ratio 14.29 %

Importance

Changes 0
Metric Value
cc 8
eloc 14
nc 3
nop 1
dl 3
loc 21
rs 7.1428
c 0
b 0
f 0
1
<?php
2
3
namespace OpenOauth\Core;
4
5
class Tools
6
{
7
    /**
8
     * 记录日志
9
     *
10
     * @param $title
11
     * @param $data
12
     * @param $path
13
     *
14
     * @return int
15
     */
16
    public static function dataRecodes($title, $data, $path)
17
    {
18
        return dataRecodes($title, $data, $path);
19
    }
20
21
    /**
22
     * 验证签名 成功 true 失败 false
23
     *
24
     * @param $token
25
     *
26
     * @return bool
27
     */
28
    public static function verifySignature($token)
0 ignored issues
show
Coding Style introduced by
verifySignature uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
29
    {
30
        $signature = $_GET['signature'];
31
        $timestamp = $_GET['timestamp'];
32
        $nonce     = $_GET['nonce'];
33
34 View Code Duplication
        if (!is_string($signature) || !is_numeric($timestamp) || $timestamp <= 0 || !is_string($nonce) || $nonce == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            return false;
36
        }
37
38
        $tmpArr = [$token, $timestamp, $nonce];
39
        sort($tmpArr, SORT_STRING);
40
        $tmpStr = implode($tmpArr);
41
        $tmpStr = sha1($tmpStr);
42
43
        if ($tmpStr == $signature && $signature != null) {
44
            return true;
45
        } else {
46
            return false;
47
        }
48
    }
49
}