@@ -88,40 +88,32 @@ public static function resetAll(): void {
88
88
*
89
89
* @return mixed The formatted time, formatted by the formatter string passed for $format.
90
90
* @throws LogicException
91
- * If the timer was not started, a \LogicException will be thrown. Use @see \Ayesh\PHP_Timer\ Timer::start()
91
+ * If the timer was not started, a \LogicException will be thrown. Use @see Timer::start
92
92
* to start a timer.
93
93
*/
94
- public static function read (string $ key = 'default ' , $ format = self ::FORMAT_MILLISECONDS ) {
95
- if (isset (self ::$ timers [$ key ])) {
96
- return self :: formatTime ( self :: $ timers [ $ key]-> read (), $ format );
94
+ public static function read (string $ key = 'default ' , string $ format = self ::FORMAT_MILLISECONDS ): string {
95
+ if (! isset (self ::$ timers [$ key ])) {
96
+ throw new LogicException ( ' Reading timer when the given key timer was not initialized. ' );
97
97
}
98
98
99
- throw new LogicException ( ' Reading timer when the given key timer was not initialized. ' );
99
+ return self :: formatTime ( self :: $ timers [ $ key]-> read (), $ format );
100
100
}
101
101
102
102
/**
103
103
* Formats the given time the processor into the given format.
104
104
*
105
105
* @param float $value
106
- * @param string|bool $format
106
+ * @param string $format
107
107
*
108
108
* @return string
109
109
*/
110
- private static function formatTime (float $ value , $ format ): string {
111
- switch ($ format ) {
112
- case static ::FORMAT_MILLISECONDS :
113
- return (string ) round ($ value * 1000 , 2 );
114
-
115
- case static ::FORMAT_SECONDS :
116
- return (string ) round ($ value , 3 );
117
-
118
- case static ::FORMAT_HUMAN :
119
- return static ::secondsToTimeString ($ value );
120
-
121
- case static ::FORMAT_PRECISE :
122
- default :
123
- return (string ) ($ value * 1000 );
124
- }
110
+ private static function formatTime (float $ value , string $ format ): string {
111
+ return match ($ format ) {
112
+ static ::FORMAT_MILLISECONDS => (string ) round ($ value * 1000 , 2 ),
113
+ static ::FORMAT_SECONDS => (string ) round ($ value , 3 ),
114
+ static ::FORMAT_HUMAN => static ::secondsToTimeString ($ value ),
115
+ default => (string ) ($ value * 1000 ),
116
+ };
125
117
}
126
118
127
119
private static function secondsToTimeString (float $ time ): string {
0 commit comments