Test Setup Failed
Push — develop ( 7cd2b2...750858 )
by Alec
03:42
created

HRTimer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkEnvironment() 0 15 4
A current() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools;
4
5
use const AlecRabbit\Helpers\Constants\INT_SIZE_64BIT;
6
7
class HRTimer extends AbstractTimer
8
{
9
    public const VALUE_COEFFICIENT = HRTIMER_VALUE_COEFFICIENT;
10
11
    /** @var bool */
12
    public static $ignoreVersionRestrictions = false;
13
14
    /**
15
     * @return int
16
     */
17
    public function current(): int
18
    {
19
        return
20
            (int)hrtime(true);
21
    }
22
23
    protected function checkEnvironment(): void
24
    {
25
        if (PHP_VERSION_ID < 70300 && false === static::$ignoreVersionRestrictions) {
26
            // `HRTimer::class` uses `hrtime()` function of PHP ^7.3.
27
            // There is almost no sense in using polyfill function.
28
            // If you're REALLY need to use HRTimer set `$ignoreVersionRestrictions` to true.
29
            // Otherwise use `Timer::class` instance instead.
30
            throw new \RuntimeException('[' . static::class . '] Your php version is below 7.3.0.');
31
        }
32
        // @codeCoverageIgnoreStart
33
        if (PHP_INT_SIZE < INT_SIZE_64BIT) {
34
            // `HRTimer::class` is designed and tested in 64bit environment
35
            // So it can be used in 64bit environments only
36
            // Maybe with some minor modification it can run on 32bit installations too
37
            throw new \RuntimeException(' You\'re using 32bit php installation.');
38
        }
39
        // @codeCoverageIgnoreEnd
40
    }
41
}
42