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

azjezz / psl / 23118021438

15 Mar 2026 07:52PM UTC coverage: 96.828% (+0.5%) from 96.352%
23118021438

push

github

web-flow
fix(async): avoid memory leak on cancellation tokens (#644)

17 of 18 new or added lines in 2 files covered. (94.44%)

2 existing lines in 1 file now uncovered.

10716 of 11067 relevant lines covered (96.83%)

35.78 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;
12✔
28

29
    if (null === $offset) {
12✔
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;
12✔
43
    $highResolutionTime = hrtime();
12✔
44
    if (false === $highResolutionTime) {
12✔
45
        throw new Psl\Exception\InvariantViolationException('The system does not provide a monotonic timer.');
×
46
    }
47

48
    [$seconds, $nanoseconds] = $highResolutionTime;
12✔
49

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

59
    $seconds += $seconds_offset;
12✔
60
    $nanoseconds = $nanosecondsAdjusted;
12✔
61

62
    return [$seconds, $nanoseconds];
12✔
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