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

azjezz / psl / 13465336729

21 Feb 2025 09:14PM UTC coverage: 98.446% (-0.04%) from 98.483%
13465336729

push

github

web-flow
chore: update mago and fix remaining override attribute issues (#508)

Signed-off-by: azjezz <azjezz@protonmail.com>

5385 of 5470 relevant lines covered (98.45%)

50.79 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
 * @mago-ignore best-practices/no-boolean-literal-comparison
27
 * @mago-ignore best-practices/no-else-clause
28
 */
29
function high_resolution_time(): array
30
{
31
    /**
32
     * @var null|array{int, int} $offset
33
     */
34
    static $offset = null;
3✔
35

36
    if ($offset === null) {
3✔
37
        $offset = hrtime();
1✔
38

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

42
        $time = system_time();
1✔
43

44
        $offset = [
1✔
45
            $time[0] - $offset[0],
1✔
46
            $time[1] - $offset[1],
1✔
47
        ];
1✔
48
    }
49

50
    [$seconds_offset, $nanoseconds_offset] = $offset;
3✔
51
    [$seconds, $nanoseconds] = hrtime();
3✔
52

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

62
    $seconds += $seconds_offset;
3✔
63
    $nanoseconds = $nanoseconds_adjusted;
3✔
64

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