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.

Timer::end()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 2
b 1
f 0
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * Class Timer
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
10
namespace icy2003\php\ihelpers;
11
12
/**
13
 * 计时器
14
 */
15
class Timer
16
{
17
    /**
18
     * 计数器
19
     *
20
     * @var array
21
     */
22
    protected static $_timers = [];
23
24
    /**
25
     * 计时开始
26
     *
27
     * @param string $name 开始名
28
     *
29
     * @return string
30
     */
31
    public static function start($name = '')
32
    {
33
        $start = microtime(true);
34
        if (empty($name)) {
35
            $name = md5($start . rand(0, 100));
36
        }
37
        static::$_timers[$name] = $start;
38
39
        return $name;
40
    }
41
42
    /**
43
     * 计时结束
44
     *
45
     * @param string $name 结束名
46
     *
47
     * @return float
48
     */
49
    public static function end($name)
50
    {
51
        $delta = 0.0;
52
        if (isset(static::$_timers[$name])) {
53
            $delta = microtime(true) - static::$_timers[$name];
54
            unset(static::$_timers[$name]);
55
        }
56
57
        return $delta;
58
    }
59
60
    /**
61
     * 计时器
62
     *
63
     * @return float
64
     */
65
    public static function timer()
66
    {
67
        static $time = 0;
68
        $previousTime = $time;
69
        $time = microtime(true);
70
71
        return (0 === $previousTime) ? 0.0 : ($time - $previousTime);
72
    }
73
}
74