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

azjezz / psl / 18800616230

25 Oct 2025 08:24AM UTC coverage: 98.445% (+0.001%) from 98.444%
18800616230

Pull #549

github

web-flow
Merge 80121fd52 into 8b9628958
Pull Request #549: Add support for PHP 8.5

17 of 17 new or added lines in 6 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

6269 of 6368 relevant lines covered (98.45%)

48.79 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:best-practices/no-else-clause
21
 * @mago-expect lint:strictness/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✔
UNCOV
53
        ++$seconds;
×
UNCOV
54
        $nanoseconds_adjusted -= NANOSECONDS_PER_SECOND;
×
55
    } elseif ($nanoseconds_adjusted < 0) {
3✔
56
        --$seconds;
1✔
57
        $nanoseconds_adjusted += NANOSECONDS_PER_SECOND;
1✔
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