Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 16, 2025
1 parent 30a91f0 commit 0abcd46
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Tracy/BlueScreen/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private function renderActions(\Throwable $ex): array
}
}

if (preg_match('# ([\'"])((?:/|[a-z]:[/\\\\])\w[^\'"]+\.\w{2,5})\1#i', $ex->getMessage(), $m)) {
if (preg_match('# ([\'"])((?:/|[a-z]:[/\\\])\w[^\'"]+\.\w{2,5})\1#i', $ex->getMessage(), $m)) {
$file = $m[2];
if (@is_file($file)) { // @ - may trigger error
$label = 'open';
Expand Down Expand Up @@ -380,14 +380,14 @@ public function formatMessage(\Throwable $exception): string

// highlight 'string'
$msg = preg_replace(
'#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#',
'#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\")*\S"#',
'<i>$0</i>',
$msg,
);

// clickable class & methods
$msg = preg_replace_callback(
'#(\w+\\\\[\w\\\\]+\w)(?:::(\w+))?#',
'#(\w+\\\[\w\\\]+\w)(?:::(\w+))?#',
function ($m) {
if (isset($m[2]) && method_exists($m[1], $m[2])) {
$r = new \ReflectionMethod($m[1], $m[2]);
Expand All @@ -406,7 +406,7 @@ function ($m) {

// clickable file name
$msg = preg_replace_callback(
'#([\w\\\\/.:-]+\.(?:php|phpt|phtml|latte|neon))(?|:(\d+)| on line (\d+))?#',
'#([\w\\\/.:-]+\.(?:php|phpt|phtml|latte|neon))(?|:(\d+)| on line (\d+))?#',
fn($m) => @is_file($m[1]) // @ - may trigger error
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri($m[1], isset($m[2]) ? (int) $m[2] : null)) . '" class="tracy-editor">' . $m[0] . '</a>'
: $m[0],
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function enable(
self::$logDirectory = $logDirectory ?? self::$logDirectory;

if (self::$logDirectory) {
if (!preg_match('#([a-z]+:)?[/\\\\]#Ai', self::$logDirectory)) {
if (!preg_match('#([a-z]+:)?[/\\\]#Ai', self::$logDirectory)) {
self::exceptionHandler(new \RuntimeException('Logging directory must be absolute path.'));
exit(255);
} elseif (!is_dir(self::$logDirectory)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,28 @@ public static function improveException(\Throwable $e): void
$message = str_replace($m[2], "but function '$arg' does not exist" . ($hint ? " (did you mean $hint?)" : ''), $message);
}

} elseif (preg_match('#^Call to undefined function (\S+\\\\)?(\w+)\(#', $message, $m)) {
} elseif (preg_match('#^Call to undefined function (\S+\\\)?(\w+)\(#', $message, $m)) {
$funcs = array_merge(get_defined_functions()['internal'], get_defined_functions()['user']);
if ($hint = self::getSuggestion($funcs, $m[1] . $m[2]) ?: self::getSuggestion($funcs, $m[2])) {
$message = "Call to undefined function $m[2](), did you mean $hint()?";
$replace = ["$m[2](", "$hint("];
}

} elseif (preg_match('#^Call to undefined method ([\w\\\\]+)::(\w+)#', $message, $m)) {
} elseif (preg_match('#^Call to undefined method ([\w\\\]+)::(\w+)#', $message, $m)) {
if ($hint = self::getSuggestion(get_class_methods($m[1]) ?: [], $m[2])) {
$message .= ", did you mean $hint()?";
$replace = ["$m[2](", "$hint("];
}

} elseif (preg_match('#^Undefined property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
} elseif (preg_match('#^Undefined property: ([\w\\\]+)::\$(\w+)#', $message, $m)) {
$rc = new \ReflectionClass($m[1]);
$items = array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($prop) => !$prop->isStatic());
if ($hint = self::getSuggestion($items, $m[2])) {
$message .= ", did you mean $$hint?";
$replace = ["->$m[2]", "->$hint"];
}

} elseif (preg_match('#^Access to undeclared static property:? ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
} elseif (preg_match('#^Access to undeclared static property:? ([\w\\\]+)::\$(\w+)#', $message, $m)) {
$rc = new \ReflectionClass($m[1]);
$items = array_filter($rc->getProperties(\ReflectionProperty::IS_STATIC), fn($prop) => $prop->isPublic());
if ($hint = self::getSuggestion($items, $m[2])) {
Expand Down Expand Up @@ -232,7 +232,7 @@ public static function improveException(\Throwable $e): void
/** @internal */
public static function improveError(string $message): string
{
if (preg_match('#^Undefined property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
if (preg_match('#^Undefined property: ([\w\\\]+)::\$(\w+)#', $message, $m)) {
$rc = new \ReflectionClass($m[1]);
$items = array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($prop) => !$prop->isStatic());
$hint = self::getSuggestion($items, $m[2]);
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getExceptionFile(\Throwable $exception, string $level = self::EX
}

$hash = substr(md5(serialize($data)), 0, 10);
$dir = strtr($this->directory . '/', '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
$dir = strtr($this->directory . '/', '\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
foreach (new \DirectoryIterator($this->directory) as $file) {
if (strpos($file->getBasename(), $hash)) {
return $dir . $file;
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.E_COMPILE_ERROR.console.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ register_shutdown_function(function () use (&$onFatalErrorCalled) {
Assert::true($onFatalErrorCalled);
Assert::match('ErrorException: Cannot re-assign $this in %a%
Stack trace:
#0 [internal function]: Tracy\\Debugger::shutdownHandler()
#0 [internal function]: Tracy\Debugger::shutdownHandler()
#1 {main}
Tracy is unable to log error: Logging directory is not specified.
', ob_get_clean());
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.barDump().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Debugger::enable();

register_shutdown_function(function () {
$output = ob_get_clean();
preg_match('#Tracy\.Debug\.init\((".*[^\\\\]")\)#', $output, $m);
preg_match('#Tracy\.Debug\.init\((".*[^\\\]")\)#', $output, $m);
$rawContent = str_replace('<\!--', '<!--', $m[1], $count);
$rawContent = json_decode($rawContent);
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-dumps')[0]['data-tracy-content'];
Expand Down
4 changes: 2 additions & 2 deletions tests/Tracy/Debugger.barDump().showLocation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Debugger::enable();

register_shutdown_function(function () {
$output = ob_get_clean();
preg_match('#Tracy\.Debug\.init\((".*[^\\\\]")\)#', $output, $m);
preg_match('#Tracy\.Debug\.init\((".*[^\\\]")\)#', $output, $m);
$rawContent = json_decode($m[1]);
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-dumps')[0]['data-tracy-content'];
Assert::match(<<<'XX'
Expand All @@ -36,7 +36,7 @@ register_shutdown_function(function () {
<div class="tracy-inner tracy-DumpPanel">
<pre class="tracy-dump tracy-light"
><a href="editor:%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump('value') 📍</a
><a href="editor:%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump('value') 📍</a
><span class="tracy-dump-string" title="5 characters"><span>'</span>value<span>'</span></span></pre>
</div>
%A%
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.warnings.html.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Debugger::enable();

register_shutdown_function(function () {
$output = ob_get_clean();
preg_match('#Tracy\.Debug\.init\((".*[^\\\\]")\)#', $output, $m);
preg_match('#Tracy\.Debug\.init\((".*[^\\\]")\)#', $output, $m);
$rawContent = json_decode($m[1]);
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-errors')[0]['data-tracy-content'];
Assert::match(<<<'XX'
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Dumper.toHtml().live.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Assert::same([], Dumper::$liveSnapshot[0]);

// live dump of array
Assert::match(
'<pre class="tracy-dump" data-tracy-dump=\'[[0,null],[1,true],[2,false],[3,0],[4,{"number":"0.0"}],[5,"string"],[6,{"string":"\u0027\u0026amp;\"","length":3}],[7,{"string":"<i>\\\\x00</i>","length":1}],[8,{"number":"INF"}],[9,{"number":"-INF"}],[10,{"number":"NAN"}]]\'></pre>',
'<pre class="tracy-dump" data-tracy-dump=\'[[0,null],[1,true],[2,false],[3,0],[4,{"number":"0.0"}],[5,"string"],[6,{"string":"\u0027\u0026amp;\"","length":3}],[7,{"string":"<i>\\\x00</i>","length":1}],[8,{"number":"INF"}],[9,{"number":"-INF"}],[10,{"number":"NAN"}]]\'></pre>',
Dumper::toHtml([null, true, false, 0, 0.0, 'string', "'&\"", "\x00", INF, -INF, NAN], $options),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Dumper.toHtml().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Assert::same('<pre class="tracy-dump tracy-light"><span class="tracy-dump-string

Assert::same('<pre class="tracy-dump tracy-light"><span class="tracy-dump-string"><span>\'</span>0<span>\'</span></span></pre>' . "\n", Dumper::toHtml('0'));

Assert::same('<pre class="tracy-dump tracy-light"><span class="tracy-dump-string"><span>\'</span><i>\\x00</i><span>\'</span></span></pre>' . "\n", Dumper::toHtml("\x00"));
Assert::same('<pre class="tracy-dump tracy-light"><span class="tracy-dump-string"><span>\'</span><i>\x00</i><span>\'</span></span></pre>' . "\n", Dumper::toHtml("\x00"));

Assert::match('<pre class="tracy-dump tracy-light"
><div class="tracy-dump-string" title="3 characters"><span class="tracy-dump-lq">\'</span>a<i>\n</i>' . "\n<span class=\"tracy-dump-indent\"> </span>b<span>'</span></div></pre>\n", Dumper::toHtml("a\nb"));
Expand Down
4 changes: 2 additions & 2 deletions tests/Tracy/expected/Debugger.barDump().expect
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<div class="tracy-inner tracy-DumpPanel">

<pre class="tracy-dump tracy-light" data-tracy-snapshot='{"%d%":{"object":"stdClass","items":[["key1","val1",3],["key2",true,3]]}}' data-tracy-dump='[[0,10],[1,20.2],[2,true],[3,false],[4,null],[5,{"string":"hello \u0026lt;!-- \u0026lt;script> \u0026lt;/script>","length":29}],[6,[["key1","val1"],["key2",true]]],[7,{"ref":%d%}]]'
><a href="editor://open/?file=%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump($arr) 📍</a
><a href="editor://open/?file=%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump($arr) 📍</a
></pre>
<h2>String</h2>

<pre class="tracy-dump tracy-light" data-tracy-snapshot='[]' data-tracy-dump='{"string":"\u0026lt;a href=\"#\">test\u0026lt;/a>","length":20}'
><a href="editor://open/?file=%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump('&lt;a href="#">test&lt;/a>', 'String') 📍</a
><a href="editor://open/?file=%a%" class="tracy-dump-location" title="in file %a% on line %d%&#10;Click to open in editor">barDump('&lt;a href="#">test&lt;/a>', 'String') 📍</a
></pre>
</div>

Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function getTempDir(): string
{
$dir = __DIR__ . '/tmp/' . getmypid();

if (empty($GLOBALS['\\lock'])) {
if (empty($GLOBALS['\lock'])) {
// garbage collector
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
$GLOBALS['\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
if (rand(0, 100)) {
flock($lock, LOCK_SH);
@mkdir(dirname($dir));
Expand Down

0 comments on commit 0abcd46

Please sign in to comment.