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

azjezz / psl / 20648259248

02 Jan 2026 12:42AM UTC coverage: 98.437%. Remained the same
20648259248

Pull #566

github

web-flow
Merge 306ffba4b into f0a0400cf
Pull Request #566: fix(tree): explicit type precedence

6299 of 6399 relevant lines covered (98.44%)

48.6 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-else-clause
21
 * @mago-expect lint:no-shorthand-ternary
22
 */
23
function high_resolution_time(): array
24
{
25
    /**
26
     * @var null|list{int, int} $offset
27
     */
28
    static $offset = null;
3✔
29

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

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

35
        $time = system_time();
1✔
36

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

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

49
    [$seconds, $nanoseconds] = $high_resolution_time;
3✔
50

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

60
    $seconds += $seconds_offset;
3✔
61
    $nanoseconds = $nanoseconds_adjusted;
3✔
62

63
    return [$seconds, $nanoseconds];
3✔
64
}
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