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

nette / neon / 25702243303

11 May 2026 10:57PM UTC coverage: 97.925% (-0.6%) from 98.485%
25702243303

push

github

dg
used attribute Deprecated

472 of 482 relevant lines covered (97.93%)

0.98 hits per line

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

96.55
/src/Neon/Traverser.php
1
<?php declare(strict_types=1);
1✔
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Neon;
9

10

11
/** @internal */
12
final class Traverser
13
{
14
        public const DontTraverseChildren = 1;
15
        public const StopTraversal = 2;
16

17
        /** @var ?(\Closure(Node): (Node|int|null)) */
18
        private ?\Closure $enter = null;
19

20
        /** @var ?(\Closure(Node): (Node|int|null)) */
21
        private ?\Closure $leave = null;
22

23
        private ?bool $stop = null;
24

25

26
        /**
27
         * @param  ?(callable(Node): (Node|int|null))  $enter
28
         * @param  ?(callable(Node): (Node|int|null))  $leave
29
         */
30
        public function traverse(Node $node, ?callable $enter = null, ?callable $leave = null): Node
1✔
31
        {
32
                $this->enter = $enter ? $enter(...) : null;
1✔
33
                $this->leave = $leave ? $leave(...) : null;
1✔
34
                $this->stop = false;
1✔
35
                return $this->traverseNode($node);
1✔
36
        }
37

38

39
        private function traverseNode(Node $node): Node
1✔
40
        {
41
                $children = true;
1✔
42
                if ($this->enter) {
1✔
43
                        $res = ($this->enter)($node);
1✔
44
                        if ($res instanceof Node) {
1✔
45
                                $node = $res;
1✔
46

47
                        } elseif ($res === self::DontTraverseChildren) {
1✔
48
                                $children = false;
1✔
49

50
                        } elseif ($res === self::StopTraversal) {
1✔
51
                                $this->stop = true;
1✔
52
                                $children = false;
1✔
53
                        }
54
                }
55

56
                if ($children) {
1✔
57
                        foreach ($node as &$subnode) {
1✔
58
                                $subnode = $this->traverseNode($subnode);
1✔
59
                                if ($this->stop) {
1✔
60
                                        break;
1✔
61
                                }
62
                        }
63
                }
64

65
                if (!$this->stop && $this->leave) {
1✔
66
                        $res = ($this->leave)($node);
1✔
67
                        if ($res instanceof Node) {
1✔
68
                                $node = $res;
×
69
                        } elseif ($res === self::StopTraversal) {
1✔
70
                                $this->stop = true;
1✔
71
                        }
72
                }
73

74
                return $node;
1✔
75
        }
76
}
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