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

nette / application / 20921730768

12 Jan 2026 01:49PM UTC coverage: 84.059% (+0.02%) from 84.039%
20921730768

push

github

dg
normalized callable to Closure

5 of 5 new or added lines in 3 files covered. (100.0%)

134 existing lines in 9 files now uncovered.

2009 of 2390 relevant lines covered (84.06%)

0.84 hits per line

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

53.45
/src/Bridges/ApplicationTracy/RoutingPanel.php
1
<?php
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
declare(strict_types=1);
9

10
namespace Nette\Bridges\ApplicationTracy;
11

12
use Nette;
13
use Nette\Application\UI\Presenter;
14
use Nette\Routing;
15
use Tracy;
16

17

18
/**
19
 * Routing debugger for Debug Bar.
20
 */
21
final class RoutingPanel implements Tracy\IBarPanel
22
{
23
        /** @var array{path: string, domain: ?string, module: string, routes: array<mixed>} */
24
        private array $routes;
25

26
        /** @var array<string, mixed>|null */
27
        private ?array $matched = null;
28

29

30
        public function __construct(
1✔
31
                private readonly Routing\Router $router,
32
                private readonly Nette\Http\IRequest $httpRequest,
33
                private readonly Nette\Application\IPresenterFactory $presenterFactory,
34
        ) {
35
        }
1✔
36

37

38
        /**
39
         * Renders tab.
40
         */
41
        public function getTab(): string
42
        {
43
                $this->routes = $this->analyse(
×
44
                        $this->router instanceof Routing\RouteList
×
UNCOV
45
                                ? $this->router
×
46
                                : (new Routing\RouteList)->add($this->router),
×
UNCOV
47
                        $this->httpRequest,
×
48
                );
49
                return Nette\Utils\Helpers::capture(function () {
×
50
                        $matched = $this->matched;
51
                        require __DIR__ . '/dist/tab.phtml';
UNCOV
52
                });
×
53
        }
54

55

56
        /**
57
         * Renders panel.
58
         */
59
        public function getPanel(): string
60
        {
UNCOV
61
                return Nette\Utils\Helpers::capture(function () {
×
62
                        $matched = $this->matched;
63
                        $routes = $this->routes;
64
                        $source = $this->matched ? $this->findSource() : null;
65
                        $url = $this->httpRequest->getUrl();
66
                        $method = $this->httpRequest->getMethod();
67
                        require __DIR__ . '/dist/panel.phtml';
UNCOV
68
                });
×
69
        }
70

71

72
        /** @return array{path: string, domain: ?string, module: string, routes: array<mixed>} */
73
        private function analyse(Routing\RouteList $router, ?Nette\Http\IRequest $httpRequest): array
1✔
74
        {
75
                $res = [
1✔
76
                        'path' => $router->getPath(),
1✔
77
                        'domain' => $router->getDomain(),
1✔
78
                        'module' => ($router instanceof Nette\Application\Routers\RouteList ? $router->getModule() : ''),
1✔
79
                        'routes' => [],
80
                ];
81
                $httpRequest = $httpRequest
1✔
82
                        ? (fn() => $this->prepareRequest($httpRequest))->bindTo($router, Routing\RouteList::class)()
1✔
UNCOV
83
                        : null;
×
84
                $flags = $router->getFlags();
1✔
85

86
                foreach ($router->getRouters() as $i => $innerRouter) {
1✔
87
                        if ($innerRouter instanceof Routing\RouteList) {
1✔
88
                                $res['routes'][] = $this->analyse($innerRouter, $httpRequest);
1✔
89
                                continue;
1✔
90
                        }
91

92
                        $matched = $flags[$i] & $router::ONE_WAY ? 'oneway' : 'no';
1✔
93
                        $params = $e = null;
1✔
94
                        try {
95
                                if (
96
                                        $httpRequest
1✔
97
                                        && ($params = $innerRouter->match($httpRequest)) !== null
1✔
98
                                        && ($params = (fn() => $this->completeParameters($params))->bindTo($router, Routing\RouteList::class)()) !== null
1✔
99
                                ) {
100
                                        $matched = 'may';
1✔
101
                                        if ($this->matched === null) {
1✔
102
                                                $this->matched = $params;
1✔
103
                                                $matched = 'yes';
1✔
104
                                        }
105
                                }
UNCOV
106
                        } catch (\Throwable $e) {
×
UNCOV
107
                                $matched = 'error';
×
108
                        }
109

110
                        $res['routes'][] = (object) [
1✔
111
                                'matched' => $matched,
1✔
112
                                'class' => $innerRouter::class,
1✔
113
                                'defaults' => $innerRouter instanceof Routing\Route || $innerRouter instanceof Routing\SimpleRouter ? $innerRouter->getDefaults() : [],
1✔
114
                                'mask' => $innerRouter instanceof Routing\Route ? $innerRouter->getMask() : null,
1✔
115
                                'params' => $params,
1✔
116
                                'error' => $e,
1✔
117
                        ];
118
                }
119
                return $res;
1✔
120
        }
121

122

123
        private function findSource(): \ReflectionClass|\ReflectionMethod|string|null
124
        {
125
                $params = $this->matched;
×
126
                $presenter = $params['presenter'] ?? '';
×
127
                try {
UNCOV
128
                        $class = $this->presenterFactory->getPresenterClass($presenter);
×
129
                } catch (Nette\Application\InvalidPresenterException) {
×
UNCOV
130
                        if ($this->presenterFactory instanceof Nette\Application\PresenterFactory) {
×
UNCOV
131
                                return $this->presenterFactory->formatPresenterClass($presenter);
×
132
                        }
133
                        return null;
×
134
                }
135

136
                if (is_a($class, Nette\Application\UI\Presenter::class, allow_string: true)) {
×
137
                        $rc = $class::getReflection();
×
UNCOV
138
                        if (isset($params[Presenter::SignalKey])) {
×
139
                                return $rc->getSignalMethod($params[Presenter::SignalKey]);
×
UNCOV
140
                        } elseif (isset($params[Presenter::ActionKey])
×
UNCOV
141
                                && ($method = $rc->getActionRenderMethod($params[Presenter::ActionKey]))
×
142
                        ) {
143
                                return $method;
×
144
                        }
145
                }
146

UNCOV
147
                return new \ReflectionClass($class);
×
148
        }
149
}
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