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

nette / tracy / 32146765344

18 Aug 2026 02:10PM UTC coverage: 57.601% (+52.1%) from 5.473%
32146765344

Pull #623

github

web-flow
Merge b964e2f41 into 0172e1b9d
Pull Request #623: Bar: info panel gets OPcache status without the scripts table

1599 of 2776 relevant lines covered (57.6%)

0.58 hits per line

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

41.51
/src/Tracy/Debugger/DevelopmentStrategy.php
1
<?php declare(strict_types=1);
2

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

8
namespace Tracy;
9

10
use ErrorException;
11
use function is_bool;
12

13

14
/**
15
 * @internal
16
 */
17
final class DevelopmentStrategy
18
{
19
        private bool $assetsSent = false;
20

21

22
        public function __construct(
1✔
23
                private readonly Bar $bar,
24
                private readonly BlueScreen $blueScreen,
25
                private readonly DeferredContent $defer,
26
        ) {
27
        }
1✔
28

29

30
        public function initialize(): void
31
        {
32
                $this->bar->getPanel('Tracy:info')->cpuUsage = function_exists('getrusage')
1✔
33
                        ? (getrusage() ?: null)
1✔
34
                        : null;
×
35
        }
1✔
36

37

38
        public function handleException(\Throwable $exception, bool $firstTime): void
39
        {
40
                if ($this->defer->isDeferred() && $this->defer->isAvailable()) {
×
41
                        $this->blueScreen->renderToAjax($exception, $this->defer);
×
42

43
                } elseif ($firstTime && Helpers::isHtmlMode()) {
×
44
                        $this->blueScreen->render($exception);
×
45

46
                } else {
47
                        $this->renderExceptionCli($exception);
×
48
                }
49
        }
50

51

52
        private function renderExceptionCli(\Throwable $exception): void
53
        {
54
                $escape = fn(string $s): string => Helpers::isHtmlMode() // exception message may contain user input
×
55
                        ? '<pre>' . Helpers::escapeHtml($s) . '</pre>'
56
                        : $s;
57

58
                try {
59
                        $logFile = Debugger::log($exception, Debugger::EXCEPTION);
×
60
                } catch (\Throwable $e) {
×
61
                        echo $escape("$exception\nTracy is unable to log error: {$e->getMessage()}\n");
×
62
                        return;
×
63
                }
64

65
                if ($logFile && !headers_sent()) {
×
66
                        header("X-Tracy-Error-Log: $logFile", replace: false);
×
67
                }
68

69
                if (Helpers::isAgent() && !Helpers::isCli() && !Helpers::isHtmlMode()) {
×
70
                        // non-HTML HTTP response for an agent carries the markdown report directly in the body
71
                        echo $this->blueScreen->renderAgent($exception) . ($logFile ? "\n(stored in $logFile)\n" : '');
×
72
                        return;
×
73
                }
74

75
                if (Helpers::detectColors() && @is_file($exception->getFile())) {
×
76
                        echo "\n\n" . CodeHighlighter::highlightPhpCli((string) file_get_contents($exception->getFile()), $exception->getLine()) . "\n";
×
77
                }
78

79
                echo $escape("$exception\n" . ($logFile ? "\n(stored in $logFile)\n" : ''));
×
80
                if ($logFile && Debugger::$browser) {
×
81
                        exec(Debugger::$browser . ' ' . escapeshellarg(strtr($logFile, Debugger::$editorMapping)));
×
82
                }
83
        }
84

85

86
        public function handleError(
1✔
87
                int $severity,
88
                string $message,
89
                string $file,
90
                int $line,
91
        ): void
92
        {
93
                if (function_exists('ini_set')) {
1✔
94
                        $oldDisplay = ini_set('display_errors', '1');
1✔
95
                }
96

97
                if (
98
                        (is_bool(Debugger::$strictMode) ? Debugger::$strictMode : (Debugger::$strictMode & $severity)) // $strictMode
1✔
99
                        && !isset($_GET['_tracy_skip_error'])
1✔
100
                ) {
101
                        $e = new ErrorException($message, 0, $severity, $file, $line);
×
102
                        @$e->skippable = true; // dynamic properties are deprecated since PHP 8.2
×
103
                        Debugger::exceptionHandler($e);
×
104
                        exit(255);
×
105
                }
106

107
                $message = Helpers::errorTypeToString($severity) . ': ' . Helpers::improveError($message);
1✔
108
                $count = &$this->bar->getPanel('Tracy:warnings')->data["$file|$line|$message"];
1✔
109

110
                if (!$count++ && !Helpers::isHtmlMode() && !$this->defer->isDeferred()) {
1✔
111
                        echo "\n$message in $file on line $line\n";
1✔
112
                }
113

114
                if (function_exists('ini_set')) {
1✔
115
                        ini_set('display_errors', $oldDisplay);
1✔
116
                }
117
        }
1✔
118

119

120
        public function dispatch(): void
121
        {
122
                if (!Helpers::isCli() && $this->defer->sendAssets()) {
1✔
123
                        $this->assetsSent = true;
×
124
                        exit;
×
125
                }
126
        }
1✔
127

128

129
        public function renderLoader(): void
130
        {
131
                $this->bar->renderLoader($this->defer);
×
132
        }
133

134

135
        public function renderBar(): void
136
        {
137
                if ($this->assetsSent || Helpers::isCli()) {
1✔
138
                        return;
1✔
139
                }
140

141
                if (function_exists('ini_set')) {
×
142
                        ini_set('display_errors', '1');
×
143
                }
144

145
                $this->bar->render($this->defer);
×
146
        }
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc