@@ -22,7 +22,8 @@ discard block |
||
22 | 22 | ): string { |
23 | 23 | $verbosity ??= $this->defaultVerbosity; |
24 | 24 | $exceptions = [$exception]; |
25 | - while ($exception = $exception->getPrevious()) { |
|
25 | + while ($exception = $exception->getPrevious()) |
|
26 | + { |
|
26 | 27 | $exceptions[] = $exception; |
27 | 28 | } |
28 | 29 | |
@@ -31,7 +32,8 @@ discard block |
||
31 | 32 | $result = []; |
32 | 33 | $rootDir = \getcwd(); |
33 | 34 | |
34 | - foreach ($exceptions as $exception) { |
|
35 | + foreach ($exceptions as $exception) |
|
36 | + { |
|
35 | 37 | $file = \str_starts_with($exception->getFile(), $rootDir) |
36 | 38 | ? \substr($exception->getFile(), \strlen($rootDir) + 1) |
37 | 39 | : $exception->getFile(); |
@@ -44,9 +46,12 @@ discard block |
||
44 | 46 | $exception->getLine(), |
45 | 47 | ); |
46 | 48 | |
47 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
49 | + if ($verbosity->value >= Verbosity::DEBUG->value) |
|
50 | + { |
|
48 | 51 | $row .= $this->renderTrace($exception, new Highlighter(new PlainStyle())); |
49 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
52 | + } |
|
53 | + elseif ($verbosity->value >= Verbosity::VERBOSE->value) |
|
54 | + { |
|
50 | 55 | $row .= $this->renderTrace($exception); |
51 | 56 | } |
52 | 57 | |
@@ -64,7 +69,8 @@ discard block |
||
64 | 69 | private function renderTrace(\Throwable $e, Highlighter $h = null): string |
65 | 70 | { |
66 | 71 | $stacktrace = $this->getStacktrace($e); |
67 | - if ($stacktrace === []) { |
|
72 | + if ($stacktrace === []) |
|
73 | + { |
|
68 | 74 | return ''; |
69 | 75 | } |
70 | 76 | |
@@ -73,8 +79,10 @@ discard block |
||
73 | 79 | |
74 | 80 | $pad = \strlen((string)\count($stacktrace)); |
75 | 81 | |
76 | - foreach ($stacktrace as $i => $trace) { |
|
77 | - if (isset($trace['type'], $trace['class'])) { |
|
82 | + foreach ($stacktrace as $i => $trace) |
|
83 | + { |
|
84 | + if (isset($trace['type'], $trace['class'])) |
|
85 | + { |
|
78 | 86 | $line = \sprintf( |
79 | 87 | '%s. %s%s%s()', |
80 | 88 | \str_pad((string)((int) $i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -82,11 +90,14 @@ discard block |
||
82 | 90 | $trace['type'], |
83 | 91 | $trace['function'] |
84 | 92 | ); |
85 | - } else { |
|
93 | + } |
|
94 | + else |
|
95 | + { |
|
86 | 96 | $line = $trace['function']; |
87 | 97 | } |
88 | 98 | |
89 | - if (isset($trace['file'])) { |
|
99 | + if (isset($trace['file'])) |
|
100 | + { |
|
90 | 101 | $file = \str_starts_with($trace['file'], $rootDir) |
91 | 102 | ? \substr($trace['file'], \strlen($rootDir) + 1) |
92 | 103 | : $trace['file']; |
@@ -94,7 +105,8 @@ discard block |
||
94 | 105 | $line .= \sprintf(' at %s:%s', $file, $trace['line']); |
95 | 106 | } |
96 | 107 | |
97 | - if (\in_array($line, $this->lines, true)) { |
|
108 | + if (\in_array($line, $this->lines, true)) |
|
109 | + { |
|
98 | 110 | continue; |
99 | 111 | } |
100 | 112 | |
@@ -102,7 +114,8 @@ discard block |
||
102 | 114 | |
103 | 115 | $result .= $line . "\n"; |
104 | 116 | |
105 | - if ($h !== null && !empty($trace['file'])) { |
|
117 | + if ($h !== null && !empty($trace['file'])) |
|
118 | + { |
|
106 | 119 | $result .= $h->highlightLines( |
107 | 120 | \file_get_contents($trace['file']), |
108 | 121 | $trace['line'], |
@@ -68,7 +68,8 @@ discard block |
||
68 | 68 | $exceptions = [$exception]; |
69 | 69 | $currentE = $exception; |
70 | 70 | |
71 | - while ($exception = $exception->getPrevious()) { |
|
71 | + while ($exception = $exception->getPrevious()) |
|
72 | + { |
|
72 | 73 | $exceptions[] = $exception; |
73 | 74 | } |
74 | 75 | |
@@ -77,7 +78,8 @@ discard block |
||
77 | 78 | $result = []; |
78 | 79 | $rootDir = \getcwd(); |
79 | 80 | |
80 | - foreach ($exceptions as $exception) { |
|
81 | + foreach ($exceptions as $exception) |
|
82 | + { |
|
81 | 83 | $prefix = $currentE === $exception ? '' : 'Previous: '; |
82 | 84 | $row = $this->renderHeader( |
83 | 85 | \sprintf("%s[%s]\n%s", $prefix, $exception::class, $exception->getMessage()), |
@@ -94,14 +96,17 @@ discard block |
||
94 | 96 | $exception->getLine() |
95 | 97 | ); |
96 | 98 | |
97 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
99 | + if ($verbosity->value >= Verbosity::DEBUG->value) |
|
100 | + { |
|
98 | 101 | $row .= $this->renderTrace( |
99 | 102 | $exception, |
100 | 103 | new Highlighter( |
101 | 104 | $this->colorsSupport ? new ConsoleStyle() : new PlainStyle() |
102 | 105 | ) |
103 | 106 | ); |
104 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
107 | + } |
|
108 | + elseif ($verbosity->value >= Verbosity::VERBOSE->value) |
|
109 | + { |
|
105 | 110 | $row .= $this->renderTrace($exception); |
106 | 111 | } |
107 | 112 | |
@@ -132,7 +137,8 @@ discard block |
||
132 | 137 | |
133 | 138 | $length += $padding; |
134 | 139 | |
135 | - foreach ($lines as $line) { |
|
140 | + foreach ($lines as $line) |
|
141 | + { |
|
136 | 142 | $result .= $this->format( |
137 | 143 | "<{$style}>%s%s%s</reset>\n", |
138 | 144 | \str_repeat('', $padding + 1), |
@@ -150,7 +156,8 @@ discard block |
||
150 | 156 | private function renderTrace(\Throwable $e, Highlighter $h = null): string |
151 | 157 | { |
152 | 158 | $stacktrace = $this->getStacktrace($e); |
153 | - if (empty($stacktrace)) { |
|
159 | + if (empty($stacktrace)) |
|
160 | + { |
|
154 | 161 | return ''; |
155 | 162 | } |
156 | 163 | |
@@ -159,11 +166,13 @@ discard block |
||
159 | 166 | |
160 | 167 | $pad = \strlen((string)\count($stacktrace)); |
161 | 168 | |
162 | - foreach ($stacktrace as $i => $trace) { |
|
169 | + foreach ($stacktrace as $i => $trace) |
|
170 | + { |
|
163 | 171 | $file = null; |
164 | 172 | $classColor = 'while'; |
165 | 173 | |
166 | - if (isset($trace['file'])) { |
|
174 | + if (isset($trace['file'])) |
|
175 | + { |
|
167 | 176 | $file = \str_starts_with($trace['file'], $rootDir) |
168 | 177 | ? \substr($trace['file'], \strlen($rootDir) + 1) |
169 | 178 | : $trace['file']; |
@@ -171,7 +180,8 @@ discard block |
||
171 | 180 | $classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white'; |
172 | 181 | } |
173 | 182 | |
174 | - if (isset($trace['type'], $trace['class'])) { |
|
183 | + if (isset($trace['type'], $trace['class'])) |
|
184 | + { |
|
175 | 185 | $line = $this->format( |
176 | 186 | "<$classColor>%s.</reset> <white>%s%s%s()</reset>", |
177 | 187 | \str_pad((string)((int)$i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -179,13 +189,16 @@ discard block |
||
179 | 189 | $trace['type'], |
180 | 190 | $trace['function'] |
181 | 191 | ); |
182 | - } else { |
|
192 | + } |
|
193 | + else |
|
194 | + { |
|
183 | 195 | $line = $this->format( |
184 | 196 | ' <white>%s()</reset>', |
185 | 197 | $trace['function'] |
186 | 198 | ); |
187 | 199 | } |
188 | - if ($file !== null) { |
|
200 | + if ($file !== null) |
|
201 | + { |
|
189 | 202 | $line .= $this->format( |
190 | 203 | ' <yellow>at</reset> <green>%s</reset><yellow>:</reset><white>%s</reset>', |
191 | 204 | $file, |
@@ -193,7 +206,8 @@ discard block |
||
193 | 206 | ); |
194 | 207 | } |
195 | 208 | |
196 | - if (\in_array($line, $this->lines, true)) { |
|
209 | + if (\in_array($line, $this->lines, true)) |
|
210 | + { |
|
197 | 211 | continue; |
198 | 212 | } |
199 | 213 | |
@@ -201,7 +215,8 @@ discard block |
||
201 | 215 | |
202 | 216 | $result .= $line . "\n"; |
203 | 217 | |
204 | - if ($h !== null && !empty($trace['file'])) { |
|
218 | + if ($h !== null && !empty($trace['file'])) |
|
219 | + { |
|
205 | 220 | $result .= $h->highlightLines( |
206 | 221 | \file_get_contents($trace['file']), |
207 | 222 | $trace['line'], |
@@ -218,13 +233,19 @@ discard block |
||
218 | 233 | */ |
219 | 234 | private function format(string $format, mixed ...$args): string |
220 | 235 | { |
221 | - if (!$this->colorsSupport) { |
|
236 | + if (!$this->colorsSupport) |
|
237 | + { |
|
222 | 238 | $format = \preg_replace('/<[^>]+>/', '', $format); |
223 | - } else { |
|
224 | - $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) { |
|
239 | + } |
|
240 | + else |
|
241 | + { |
|
242 | + $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) |
|
243 | + { |
|
225 | 244 | $style = ''; |
226 | - foreach (\explode(',', \trim($partial[2], '/')) as $color) { |
|
227 | - if (isset(self::COLORS[$color])) { |
|
245 | + foreach (\explode(',', \trim($partial[2], '/')) as $color) |
|
246 | + { |
|
247 | + if (isset(self::COLORS[$color])) |
|
248 | + { |
|
228 | 249 | $style .= self::COLORS[$color]; |
229 | 250 | } |
230 | 251 | } |
@@ -243,12 +264,15 @@ discard block |
||
243 | 264 | */ |
244 | 265 | private function isColorsSupported(mixed $stream = STDOUT): bool |
245 | 266 | { |
246 | - if ('Hyper' === \getenv('TERM_PROGRAM')) { |
|
267 | + if ('Hyper' === \getenv('TERM_PROGRAM')) |
|
268 | + { |
|
247 | 269 | return true; |
248 | 270 | } |
249 | 271 | |
250 | - try { |
|
251 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
272 | + try |
|
273 | + { |
|
274 | + if (\DIRECTORY_SEPARATOR === '\\') |
|
275 | + { |
|
252 | 276 | return (\function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support($stream)) |
253 | 277 | || \getenv('ANSICON') !== false |
254 | 278 | || \getenv('ConEmuANSI') === 'ON' |
@@ -256,7 +280,9 @@ discard block |
||
256 | 280 | } |
257 | 281 | |
258 | 282 | return @\stream_isatty($stream); |
259 | - } catch (\Throwable) { |
|
283 | + } |
|
284 | + catch (\Throwable) |
|
285 | + { |
|
260 | 286 | return false; |
261 | 287 | } |
262 | 288 | } |