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

azjezz / psl / 13067986688

31 Jan 2025 07:01AM UTC coverage: 98.465% (-0.06%) from 98.52%
13067986688

push

github

web-flow
Update psalm, infection, mago, ... (#506)

13 of 14 new or added lines in 7 files covered. (92.86%)

2 existing lines in 1 file now uncovered.

5324 of 5407 relevant lines covered (98.46%)

50.86 hits per line

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

80.95
/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
 * @psalm-mutation-free
21
 *
22
 * @psalm-suppress ImpureStaticVariable - We ignore the internal mutation, as is simply a static initializer.
23
 * @psalm-suppress ImpureFunctionCall - `hrtime()` it is mutation-free, as it performs a read-only operation from the systems clock,
24
 *  and does not alter anything.
25
 */
26
function high_resolution_time(): array
27
{
28
    /**
29
     * @var null|array{int, int} $offset
30
     */
31
    static $offset = null;
3✔
32

33
    if ($offset === null) {
3✔
34
        $offset = hrtime();
1✔
35

36
        /** @psalm-suppress RedundantCondition - This is not redundant, hrtime can return false. */
37
        Psl\invariant(false !== $offset, 'The system does not provide a monotonic timer.');
1✔
38

39
        $time = system_time();
1✔
40

41
        $offset = [
1✔
42
            $time[0] - $offset[0],
1✔
43
            $time[1] - $offset[1],
1✔
44
        ];
1✔
45
    }
46

47
    [$seconds_offset, $nanoseconds_offset] = $offset;
3✔
48
    [$seconds, $nanoseconds] = hrtime();
3✔
49

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

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

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