Tools   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 6.67 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 3
loc 45
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dataRecodes() 0 4 1
B verifySignature() 3 21 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}