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 ( 20767b...6d36fd )
by Sergey
13:51
created

Timer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 8
c 4
b 1
f 2
lcom 1
cbo 0
dl 0
loc 114
ccs 22
cts 22
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 5 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 = 0;
11
12
    /**
13
     * @var string
14
     */
15
    private $format;
16
17
    /**
18
     * @var double
19
     */
20
    private $time = 0;
21
22
    /**
23
     * Create a new Timer instance and start it.
24
     *
25
     * @param string $format
26
     */
27 18
    public function __construct($format = 'H:i:s.ms')
28
    {
29 18
        $this->format($format)->start();
30 18
    }
31
32
    /**
33
     * Set the date format.
34
     *
35
     * @param string $format
36 18
     * @return $this
37
     */
38 18
    protected function format($format)
39 18
    {
40
        $this->format = $format;
41
        return $this;
42
    }
43
44
    /**
45
     * Start the timer.
46
     *
47 18
     * @return $this
48
     */
49 18
    public function start()
50 18
    {
51
        $this->start = microtime(true);
52
        return $this;
53
    }
54
55
    /**
56
     * Stop the timer.
57
     *
58 18
     * @return $this
59
     */
60 18
    public function stop()
61 18
    {
62
        $this->time += microtime(true) - $this->start;
63
        return $this;
64
    }
65
66
    /**
67
     * Reset the timer.
68
     *
69 18
     * @return $this
70
     */
71 18
    public function reset()
72 18
    {
73 18
        $this->time = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $time was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
74
        $this->start();
75 18
        return $this;
76 18
    }
77 18
78
    /**
79 18
     * Return measured time.
80
     *
81
     * @return string
82
     */
83
    public function time()
84
    {
85
        $format = $this->format;
86
87 15
        $format = $this->replace('u', 6, $format);
88
89 15
        $format = $this->replace('ms', 3, $format);
90
91
        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
    private function replace($pattern, $precision, $format)
103
    {
104
        $time = round($this->time, $precision);
105
        $value = substr(number_format($time - floor($time), $precision), 2);
106
        return str_replace($pattern, $value, $format);
107
    }
108
109
    /**
110
     * Stop the timer and return measured time.
111
     *
112
     * @return string
113
     */
114
    public function end()
115
    {
116
        return $this->stop()->time();
117
    }
118
}
119