1 | <?php |
||
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') |
|
31 | |||
32 | /** |
||
33 | * Set the date format. |
||
34 | * |
||
35 | * @param string $format |
||
36 | 18 | * @return $this |
|
37 | */ |
||
38 | 18 | protected function format($format) |
|
43 | |||
44 | /** |
||
45 | * Start the timer. |
||
46 | * |
||
47 | 18 | * @return $this |
|
48 | */ |
||
49 | 18 | public function start() |
|
54 | |||
55 | /** |
||
56 | * Stop the timer. |
||
57 | * |
||
58 | 18 | * @return $this |
|
59 | */ |
||
60 | 18 | public function stop() |
|
65 | |||
66 | /** |
||
67 | * Reset the timer. |
||
68 | * |
||
69 | 18 | * @return $this |
|
70 | */ |
||
71 | 18 | public function reset() |
|
77 | 18 | ||
78 | /** |
||
79 | 18 | * Return measured time. |
|
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function time() |
||
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) |
||
108 | |||
109 | /** |
||
110 | * Stop the timer and return measured time. |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | public function end() |
||
118 | } |
||
119 |
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.