• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

azjezz / psl / 22651694807

04 Mar 2026 02:01AM UTC coverage: 98.344% (+0.1%) from 98.238%
22651694807

push

github

web-flow
chore: increase MSI (#608)

9321 of 9478 relevant lines covered (98.34%)

39.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/Psl/DateTime/Internal/high_resolution_time.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\DateTime\Internal;
6

7
use Psl;
8

9
use function hrtime;
10

11
use const Psl\DateTime\NANOSECONDS_PER_SECOND;
12

13
/**
14
 * @throws Psl\Exception\InvariantViolationException
15
 *
16
 * @return array{int, int}
17
 *
18
 * @internal
19
 *
20
 * @mago-expect lint:no-shorthand-ternary
21
 */
22
function high_resolution_time(): array
23
{
24
    /**
25
     * @var null|list{int, int} $offset
26
     */
27
    static $offset = null;
13✔
28

29
    if (null === $offset) {
13✔
30
        $offset = hrtime() ?: null;
1✔
31

32
        Psl\invariant(null !== $offset, 'The system does not provide a monotonic timer.');
1✔
33

34
        $time = system_time();
1✔
35

36
        $offset = [
1✔
37
            $time[0] - $offset[0],
1✔
38
            $time[1] - $offset[1],
1✔
39
        ];
1✔
40
    }
41

42
    [$seconds_offset, $nanoseconds_offset] = $offset;
13✔
43
    $high_resolution_time = hrtime();
13✔
44
    if (false === $high_resolution_time) {
13✔
45
        throw new Psl\Exception\InvariantViolationException('The system does not provide a monotonic timer.');
×
46
    }
47

48
    [$seconds, $nanoseconds] = $high_resolution_time;
13✔
49

50
    $nanoseconds_adjusted = $nanoseconds + $nanoseconds_offset;
13✔
51
    if ($nanoseconds_adjusted >= NANOSECONDS_PER_SECOND) {
13✔
52
        ++$seconds;
×
53
        $nanoseconds_adjusted -= NANOSECONDS_PER_SECOND;
×
54
    } elseif ($nanoseconds_adjusted < 0) {
13✔
55
        --$seconds;
3✔
56
        $nanoseconds_adjusted += NANOSECONDS_PER_SECOND;
3✔
57
    }
58

59
    $seconds += $seconds_offset;
13✔
60
    $nanoseconds = $nanoseconds_adjusted;
13✔
61

62
    return [$seconds, $nanoseconds];
13✔
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc