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.
Completed
Push — master ( 6497d6...e69f8b )
by Sergey
08:09
created

Timer::stop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 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
        $this->time += microtime(true) - $this->start;
63 30
        return $this;
64
    }
65
66
    /**
67
     * Reset the timer.
68
     *
69
     * @return $this
70
     */
71 3
    public function reset()
72
    {
73 3
        $this->time = 0.0;
74 3
        $this->start();
75 3
        return $this;
76
    }
77
78
    /**
79
     * Return measured time.
80
     *
81
     * @return string
82
     */
83 30
    public function time()
84
    {
85 30
        $format = $this->format;
86
87 30
        $format = $this->replace('u', 6, $format);
88
89 30
        $format = $this->replace('ms', 3, $format);
90
91 30
        return gmdate($format, $this->time);
92
    }
93
94
    /**
95
     * Replace the date format with calculated values.
96
     *
97
     * @param string $pattern
98
     * @param int $precision
99
     * @param string $format
100
     * @return string
101
     */
102 30
    private function replace($pattern, $precision, $format)
103
    {
104 30
        $time = round($this->time, $precision);
105 30
        $value = substr(number_format($time - floor($time), $precision), 2);
106 30
        return str_replace($pattern, $value, $format);
107
    }
108
109
    /**
110
     * Stop the timer and return measured time.
111
     *
112
     * @return string
113
     */
114 21
    public function end()
115
    {
116 21
        return $this->stop()->time();
117
    }
118
}
119