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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 8
c 6
b 2
f 2
lcom 1
cbo 0
dl 0
loc 116
ccs 29
cts 29
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 5 1
A start() 0 5 1
A stop() 0 7 1
A reset() 0 6 1
A time() 0 10 1
A replace() 0 6 1
A end() 0 4 1
1
<?php
2
3
namespace Isswp101\Timer;
4
5
class Timer
6
{
7
    /**
8
     * @var double
9
     */
10
    private $start;
11
12
    /**
13
     * @var double
14
     */
15
    private $time;
16
17
    /**
18
     * @var string
19
     */
20
    private $format;
21
22
    /**
23
     * Create a new Timer instance and start it.
24
     *
25
     * @param string $format
26
     */
27 30
    public function __construct($format = 'H:i:s.ms')
28
    {
29 30
        $this->format($format)->start();
30 30
    }
31
32
    /**
33
     * Set the date format.
34
     *
35
     * @param string $format
36
     * @return $this
37
     */
38 30
    protected function format($format)
39
    {
40 30
        $this->format = $format;
41 30
        return $this;
42
    }
43
44
    /**
45
     * Start the timer.
46
     *
47
     * @return $this
48
     */
49 30
    public function start()
50
    {
51 30
        $this->start = microtime(true);
52 30
        return $this;
53
    }
54
55
    /**
56
     * Stop the timer.
57
     *
58
     * @return $this
59
     */
60 30
    public function stop()
61
    {
62 30
        $time = microtime(true);
63 30
        $this->time += $time - $this->start;
64 30
        $this->start = $time;
65 30
        return $this;
66
    }
67
68
    /**
69
     * Reset the timer.
70
     *
71
     * @return $this
72
     */
73 3
    public function reset()
74
    {
75 3
        $this->time = 0.0;
76 3
        $this->start();
77 3
        return $this;
78
    }
79
80
    /**
81
     * Return measured time.
82
     *
83
     * @return string
84
     */
85 30
    public function time()
86
    {
87 30
        $format = $this->format;
88
89 30
        $format = $this->replace('u', 6, $format);
90
91 30
        $format = $this->replace('ms', 3, $format);
92
93 30
        return gmdate($format, $this->time);
94
    }
95
96
    /**
97
     * Replace the date format with calculated values.
98
     *
99
     * @param string $pattern
100
     * @param int $precision
101
     * @param string $format
102
     * @return string
103
     */
104 30
    private function replace($pattern, $precision, $format)
105
    {
106 30
        $time = round($this->time, $precision);
107 30
        $value = substr(number_format($time - floor($time), $precision), 2);
108 30
        return str_replace($pattern, $value, $format);
109
    }
110
111
    /**
112
     * Stop the timer and return measured time.
113
     *
114
     * @return string
115
     */
116 21
    public function end()
117
    {
118 21
        return $this->stop()->time();
119
    }
120
}
121