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

azjezz / psl / 18746347851

23 Oct 2025 11:07AM UTC coverage: 98.519% (-0.05%) from 98.572%
18746347851

push

github

web-flow
feat: add Tree component for hierarchical data structures (#546)

Introduces a new `Tree` component providing immutable tree data structures
and functional operations for hierarchical data manipulation.

Architecture:
- NodeInterface<T>: Base interface with getValue()
- LeafNode<T>: Immutable leaf nodes (no children)
- TreeNode<T>: Immutable tree nodes with getChildren()
- Pure constructor functions: tree() and leaf()

Features:
- Transformation operations: map, filter, reduce, fold
- Traversal algorithms: pre_order, post_order, level_order
- Search functions: find, any, all, contains
- Utility functions: count, depth, is_leaf, leaves
- Path operations: path_to, at_path
- Array conversion: from_array, to_array

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

190 of 194 new or added lines in 29 files covered. (97.94%)

2 existing lines in 1 file now uncovered.

5987 of 6077 relevant lines covered (98.52%)

50.09 hits per line

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

79.17
/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✔
53
        ++$seconds;
×
54
        $nanoseconds_adjusted -= NANOSECONDS_PER_SECOND;
×
55
    } elseif ($nanoseconds_adjusted < 0) {
3✔
UNCOV
56
        --$seconds;
×
UNCOV
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