1 | <?php |
||
19 | final class Stopwatch |
||
20 | { |
||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | private $time; |
||
25 | |||
26 | /** |
||
27 | * @var float |
||
28 | */ |
||
29 | private $elapsed; |
||
30 | |||
31 | /** |
||
32 | * @var bool |
||
33 | */ |
||
34 | private $isRunning; |
||
35 | |||
36 | 5 | private function __construct() |
|
40 | |||
41 | /** |
||
42 | * @return Stopwatch |
||
43 | */ |
||
44 | 5 | public static function createNew(): self |
|
48 | |||
49 | /** |
||
50 | * Starts or resumes measurement. |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | 7 | public function start(): void |
|
59 | |||
60 | /** |
||
61 | * Stops measurement. |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | 2 | public function stop(): void |
|
70 | |||
71 | /** |
||
72 | * Stops measurement and starts from the beginning. |
||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | 1 | public function restart(): void |
|
81 | |||
82 | /** |
||
83 | * Stops measurement and resets elapsed time. |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | 1 | public function reset(): void |
|
91 | |||
92 | /** |
||
93 | * @return float |
||
94 | */ |
||
95 | 10 | public function getElapsed(): float |
|
101 | |||
102 | /** |
||
103 | * @return int |
||
104 | */ |
||
105 | 1 | public function getElapsedSeconds(): int |
|
109 | |||
110 | /** |
||
111 | * @return int |
||
112 | */ |
||
113 | 1 | public function getElapsedMilliseconds(): int |
|
117 | |||
118 | /** |
||
119 | * @return int |
||
120 | */ |
||
121 | 1 | public function getElapsedMicroseconds(): int |
|
125 | |||
126 | /** |
||
127 | * Returns true if stopwatch is running, otherwise false. |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | 6 | public function isRunning(): bool |
|
135 | |||
136 | /** |
||
137 | * Initializes stopwatch internals. |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | 7 | private function init(): void |
|
147 | |||
148 | /** |
||
149 | * Stores elapsed time. |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | 10 | private function storeElapsed(): void |
|
161 | } |
||
162 |