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

nette / latte / 22359082277

24 Feb 2026 04:03PM UTC coverage: 93.959% (+0.05%) from 93.907%
22359082277

push

github

dg
fixed operator ! priority

5273 of 5612 relevant lines covered (93.96%)

0.94 hits per line

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

96.88
/src/Latte/Compiler/NodeTraverser.php
1
<?php declare(strict_types=1);
2

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

8
namespace Latte\Compiler;
9

10

11
final class NodeTraverser
12
{
13
        public const DontTraverseChildren = 1;
14
        public const StopTraversal = 2;
15
        public const RemoveNode = 3;
16

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

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

23
        private bool $stop;
24

25

26
        public function traverse(Node $node, ?callable $enter = null, ?callable $leave = null): ?Node
1✔
27
        {
28
                $this->enter = $enter;
1✔
29
                $this->leave = $leave;
1✔
30
                $this->stop = false;
1✔
31
                return $this->traverseNode($node);
1✔
32
        }
33

34

35
        private function traverseNode(Node $node): ?Node
1✔
36
        {
37
                $children = true;
1✔
38
                if ($this->enter) {
1✔
39
                        $res = ($this->enter)($node);
1✔
40
                        if ($res instanceof Node) {
1✔
41
                                $node = $res;
1✔
42

43
                        } elseif ($res === self::DontTraverseChildren) {
1✔
44
                                $children = false;
1✔
45

46
                        } elseif ($res === self::StopTraversal) {
1✔
47
                                $this->stop = true;
1✔
48
                                return $node;
1✔
49

50
                        } elseif ($res === self::RemoveNode) {
1✔
51
                                return null;
1✔
52
                        }
53
                }
54

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

64
                if (!$this->stop && $this->leave) {
1✔
65
                        $res = ($this->leave)($node);
1✔
66
                        if ($res instanceof Node) {
1✔
67
                                $node = $res;
1✔
68

69
                        } elseif ($res === self::StopTraversal) {
1✔
70
                                $this->stop = true;
1✔
71

72
                        } elseif ($res === self::RemoveNode) {
1✔
73
                                return null;
×
74
                        }
75
                }
76

77
                return $node;
1✔
78
        }
79
}
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