• 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

66.67
/src/Psl/Tree/LeafNode.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Tree;
6

7
use Override;
8

9
/**
10
 * Immutable leaf node implementation (node with no children).
11
 *
12
 * @template T
13
 *
14
 * @implements NodeInterface<T>
15
 */
16
final readonly class LeafNode implements NodeInterface
17
{
18
    /**
19
     * @param T $value
20
     */
21
    public function __construct(
22
        private mixed $value,
23
    ) {}
92✔
24

25
    /**
26
     * @return T
27
     *
28
     * @psalm-mutation-free
29
     */
30
    #[Override]
31
    public function getValue(): mixed
32
    {
33
        return $this->value;
72✔
34
    }
35

36
    /**
37
     * @return array{value: T, ...}
38
     */
39
    #[Override]
40
    public function jsonSerialize(): array
41
    {
NEW
42
        return namespace\to_array($this);
×
43
    }
44
}
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