| Total Complexity | 8 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class Time |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Time formatting helper |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private static $times = [ |
||
| 25 | 'hour' => 3600, |
||
| 26 | 'minute' => 60, |
||
| 27 | 'second' => 1 |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Returns the time passed since execution start |
||
| 32 | * |
||
| 33 | * @throws \RuntimeException |
||
| 34 | */ |
||
| 35 | 13 | public static function timeSinceExecutionStart() : float |
|
| 36 | { |
||
| 37 | 13 | if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { |
|
| 38 | 11 | $startOfRequest = $_SERVER['REQUEST_TIME_FLOAT']; |
|
| 39 | 2 | } elseif (isset($_SERVER['REQUEST_TIME'])) { |
|
| 40 | 1 | $startOfRequest = $_SERVER['REQUEST_TIME']; |
|
| 41 | } else { |
||
| 42 | 1 | throw new RuntimeException('Cannot determine time at which the execution started'); |
|
| 43 | } |
||
| 44 | 12 | return \microtime(true) - $startOfRequest; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Return string like '1 hour 3 minutes 12 seconds' |
||
| 49 | * |
||
| 50 | * @param float $time |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 11 | public static function formatTime(float $time) : string |
|
| 65 | } |
||
| 66 | } |
||
| 67 |