Passed
Pull Request — master (#33)
by Melech
04:17 queued 54s
created

Microtime   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A time() 0 3 1
A get() 0 3 1
A freeze() 0 3 1
A unfreeze() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Support\Time;
15
16
/**
17
 * Class Microtime.
18
 *
19
 * @author Melech Mizrachi
20
 */
21
class Microtime
22
{
23
    protected static float|null $frozenTime = null;
24
25
    public static function freeze(float $microtime = null): void
26
    {
27
        static::$frozenTime = $microtime ?? static::time();
28
    }
29
30
    public static function unfreeze(): void
31
    {
32
        static::$frozenTime = null;
33
    }
34
35
    public static function get(): float
36
    {
37
        return static::$frozenTime ?? static::time();
38
    }
39
40
    protected static function time(): float
41
    {
42
        return microtime(true);
43
    }
44
}
45