Completed
Push — master ( ba86a8...110e22 )
by Alec
04:16 queued 41s
created

HRTimer::assertStop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools;
4
5
use function AlecRabbit\typeOf;
6
use const AlecRabbit\Helpers\Constants\INT_SIZE_64BIT;
7
8
class HRTimer extends AbstractTimer
9
{
10
    public const VALUE_COEFFICIENT = HRTIMER_VALUE_COEFFICIENT;
11
12
    /** @var bool */
13
    public static $ignoreVersionRestrictions = false;
14
15
    /**
16
     * @return int
17
     */
18 17
    public function current(): int
19
    {
20
        return
21 17
            (int)hrtime(true);
22
    }
23
24 21
    protected function checkEnvironment(): void
25
    {
26
        // @codeCoverageIgnoreStart
27
        if (PHP_VERSION_ID < 70300 && false === static::$ignoreVersionRestrictions) {
28
            // `HRTimer::class` uses `hrtime()` function of PHP ^7.3.
29
            // There is almost no sense in using polyfill function.
30
            // If you're REALLY need to use HRTimer set `$ignoreVersionRestrictions` to true.
31
            // Otherwise use `Timer::class` instance instead.
32
            throw new \RuntimeException('[' . static::class . '] Your php version is below 7.3.0.');
33
        }
34
        if (PHP_INT_SIZE < INT_SIZE_64BIT) {
35
            // `HRTimer::class` is designed and tested in 64bit environment
36
            // So it can be used in 64bit environments only
37
            // Maybe with some minor modification it can run on 32bit installations too
38
            throw new \RuntimeException(' You\'re using 32bit php installation.');
39
        }
40
        // @codeCoverageIgnoreEnd
41 21
    }
42
43
    /**
44
     * @param int $start
45
     * @param int $stop
46
     */
47 5
    protected function assertStartAndStop($start, $stop): void
48
    {
49 5
        $this->assertStart($start);
50 4
        $this->assertStop($stop);
51 3
    }
52
53
    /**
54
     * @param int $start
55
     */
56 4
    protected function assertStart(/** @scrutinizer ignore-unused */ int $start): void
57
    {
58
        // Intentionally left blank
59 4
    }
60
61
    /**
62
     * @param int $stop
63
     */
64 3
    protected function assertStop(/** @scrutinizer ignore-unused */ int $stop): void
65
    {
66
        // Intentionally left blank
67 3
    }
68
}
69