Skip to content

Commit fe0aae8

Browse files
committed
used native PHP 8 features
1 parent bdec6ae commit fe0aae8

15 files changed

+24
-30
lines changed

src/Bridges/Psr/PsrToTracyLoggerAdapter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
public function log(mixed $value, string $level = self::INFO)
3939
{
4040
if ($value instanceof \Throwable) {
41-
$message = Tracy\Helpers::getClass($value) . ': ' . $value->getMessage() . ($value->getCode() ? ' #' . $value->getCode() : '') . ' in ' . $value->getFile() . ':' . $value->getLine();
41+
$message = get_debug_type($value) . ': ' . $value->getMessage() . ($value->getCode() ? ' #' . $value->getCode() : '') . ' in ' . $value->getFile() . ':' . $value->getLine();
4242
$context = ['exception' => $value];
4343

4444
} elseif (!is_string($value)) {

src/Tracy/BlueScreen/BlueScreen.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ private function renderTemplate(\Throwable $exception, string $template, bool $t
148148
[$generators, $fibers] = $this->findGeneratorsAndFibers($exception);
149149
$headersSent = headers_sent($headersFile, $headersLine);
150150
$obStatus = Debugger::$obStatus;
151-
$showEnvironment = $this->showEnvironment && (strpos($exception->getMessage(), 'Allowed memory size') === false);
151+
$showEnvironment = $this->showEnvironment && (!str_contains($exception->getMessage(), 'Allowed memory size'));
152152
$info = array_filter($this->info);
153153
$source = Helpers::getSource();
154154
$title = $exception instanceof \ErrorException
155155
? Helpers::errorTypeToString($exception->getSeverity())
156-
: Helpers::getClass($exception);
156+
: get_debug_type($exception);
157157
$lastError = $exception instanceof \ErrorException || $exception instanceof \Error
158158
? null
159159
: error_get_last();
@@ -272,7 +272,7 @@ private function renderActions(\Throwable $ex): array
272272
];
273273
}
274274

275-
$query = ($ex instanceof \ErrorException ? '' : Helpers::getClass($ex) . ' ')
275+
$query = ($ex instanceof \ErrorException ? '' : get_debug_type($ex) . ' ')
276276
. preg_replace('#\'.*\'|".*"#Us', '', $ex->getMessage());
277277
$actions[] = [
278278
'link' => 'https://www.google.com/search?sourceid=tracy&q=' . urlencode($query),
@@ -527,7 +527,7 @@ private function renderPhpInfo(): void
527527
@phpinfo(INFO_CONFIGURATION | INFO_MODULES); // @ phpinfo may be disabled
528528
$info = ob_get_clean();
529529

530-
if (strpos($license, '<body') === false) {
530+
if (!str_contains($license, '<body')) {
531531
echo '<pre class="tracy-dump tracy-light">', Helpers::escapeHtml($info), '</pre>';
532532
} else {
533533
$info = str_replace('<table', '<table class="tracy-sortable"', $info);

src/Tracy/BlueScreen/assets/page.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $chain = Helpers::getExceptionChain($exception);
2525
<!-- in <?= str_replace('--', '- ', Helpers::escapeHtml($exception->getFile() . ':' . $exception->getLine())) ?> -->
2626
<?php if (count($chain) > 1): ?>
2727
<!--<?php foreach (array_slice($chain, 1) as $ex) {
28-
echo str_replace('--', '- ', Helpers::escapeHtml("\n\tcaused by " . Helpers::getClass($ex) . ': ' . $ex->getMessage() . ($ex->getCode() ? ' #' . $ex->getCode() : '')));
28+
echo str_replace('--', '- ', Helpers::escapeHtml("\n\tcaused by " . get_debug_type($ex) . ': ' . $ex->getMessage() . ($ex->getCode() ? ' #' . $ex->getCode() : '')));
2929
} ?> -->
3030
<?php endif ?>
3131

src/Tracy/BlueScreen/assets/section-exception-exception.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Tracy;
99
* @var callable $dump
1010
*/
1111

12-
if (count((array) $ex) <= count((array) new \Exception)) {
12+
if (count(get_mangled_object_vars($ex)) <= count(get_mangled_object_vars(new \Exception))) {
1313
return;
1414
}
1515
?>

src/Tracy/BlueScreen/assets/section-header.phtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Tracy;
1313

1414
$title = $ex instanceof \ErrorException
1515
? Helpers::errorTypeToString($ex->getSeverity())
16-
: Helpers::getClass($ex);
16+
: get_debug_type($ex);
1717
$code = $ex->getCode() ? ' #' . $ex->getCode() : '';
1818

1919
?>
@@ -30,6 +30,6 @@ $code = $ex->getCode() ? ' #' . $ex->getCode() : '';
3030

3131
<?php if ($ex->getPrevious()): ?>
3232
<div class="tracy-caused">
33-
<a href="#tracyCaused<?= count($exceptions) + 1 ?>">Caused by <?= Helpers::escapeHtml(Helpers::getClass($ex->getPrevious())) ?></a>
33+
<a href="#tracyCaused<?= count($exceptions) + 1 ?>">Caused by <?= Helpers::escapeHtml(get_debug_type($ex->getPrevious())) ?></a>
3434
</div>
3535
<?php endif ?>

src/Tracy/BlueScreen/assets/section-stack-callStack.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if (!$stack) {
7272
try {
7373
$r = isset($row['class']) ? new \ReflectionMethod($row['class'], $row['function']) : new \ReflectionFunction($row['function']);
7474
$params = $r->getParameters();
75-
} catch (\Exception $e) {
75+
} catch (\Exception) {
7676
$params = [];
7777
}
7878
foreach ($row['args'] as $k => $v) {

src/Tracy/Debugger/Debugger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public static function exceptionHandler(\Throwable $exception): void
308308
self::$obStatus = ob_get_status(true);
309309

310310
if (!headers_sent()) {
311-
http_response_code(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false ? 503 : 500);
311+
http_response_code(isset($_SERVER['HTTP_USER_AGENT']) && str_contains($_SERVER['HTTP_USER_AGENT'], 'MSIE ') ? 503 : 500);
312312
}
313313

314314
Helpers::improveException($exception);

src/Tracy/Dumper/Describer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function describeObject(object $obj, int $depth = 0): Value
167167
return new Value(Value::TypeRef, $id);
168168
}
169169

170-
$value = new Value(Value::TypeObject, Helpers::getClass($obj));
170+
$value = new Value(Value::TypeObject, get_debug_type($obj));
171171
$value->id = $id;
172172
$value->depth = $depth;
173173
$value->holder = $obj; // to be not released by garbage collector in collecting mode
@@ -286,7 +286,7 @@ private static function hideValue(mixed $val): string
286286
$val = $val->getValue();
287287
}
288288

289-
return self::HiddenValue . ' (' . (is_object($val) ? Helpers::getClass($val) : gettype($val)) . ')';
289+
return self::HiddenValue . ' (' . get_debug_type($val) . ')';
290290
}
291291

292292

src/Tracy/Dumper/Exposer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class Exposer
1919
{
2020
public static function exposeObject(object $obj, Value $value, Describer $describer): void
2121
{
22-
$values = (array) $obj;
22+
$values = get_mangled_object_vars($obj);
2323
$props = self::getProperties($obj::class);
2424

2525
foreach (array_diff_key($values, $props) as $k => $v) {
@@ -208,7 +208,7 @@ public static function exposePhpIncompleteClass(
208208
Describer $describer,
209209
): void
210210
{
211-
$values = (array) $obj;
211+
$values = get_mangled_object_vars($obj);
212212
$class = $values['__PHP_Incomplete_Class_Name'];
213213
unset($values['__PHP_Incomplete_Class_Name']);
214214
foreach ($values as $k => $v) {

src/Tracy/Helpers.php

-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ public static function findTrace(array $trace, array|string $method, ?int &$inde
110110
}
111111

112112

113-
public static function getClass(object $obj): string
114-
{
115-
return explode("\x00", $obj::class)[0];
116-
}
117-
118-
119113
/** @internal */
120114
public static function fixStack(\Throwable $exception): \Throwable
121115
{

src/Tracy/Logger/Logger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function formatMessage($message): string
8787
foreach (Helpers::getExceptionChain($message) as $exception) {
8888
$tmp[] = ($exception instanceof \ErrorException
8989
? Helpers::errorTypeToString($exception->getSeverity()) . ': ' . $exception->getMessage()
90-
: Helpers::getClass($exception) . ': ' . $exception->getMessage() . ($exception->getCode() ? ' #' . $exception->getCode() : '')
90+
: get_debug_type($exception) . ': ' . $exception->getMessage() . ($exception->getCode() ? ' #' . $exception->getCode() : '')
9191
) . ' in ' . $exception->getFile() . ':' . $exception->getLine();
9292
}
9393

tests/Tracy/Dumper.keysToHide.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $obj = (object) [
2525
Assert::match(
2626
<<<'XX'
2727
stdClass #%d%
28-
a: ***** (integer)
28+
a: ***** (int)
2929
password: ***** (string)
3030
PASSWORD: ***** (string)
3131
Pin: ***** (string)

tests/Tracy/Dumper.scrubber.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ $expect1 = <<<'XX'
3333
PASSWORD: 'secret2'
3434
Pin: ***** (string)
3535
foo: ***** (string)
36-
q: ***** (integer)
36+
q: ***** (int)
3737
inner: array (5)
3838
| 'a' => 123
3939
| 'password' => 'secret4'
4040
| 'PASSWORD' => 'secret5'
4141
| 'Pin' => ***** (string)
42-
| 'bar' => ***** (integer)
42+
| 'bar' => ***** (int)
4343
XX;
4444

4545
Assert::match($expect1, Dumper::toText($obj, [Dumper::SCRUBBER => $scrubber]));
@@ -52,13 +52,13 @@ $expect2 = <<<'XX'
5252
PASSWORD: ***** (string)
5353
Pin: ***** (string)
5454
foo: ***** (string)
55-
q: ***** (integer)
55+
q: ***** (int)
5656
inner: array (5)
5757
| 'a' => 123
5858
| 'password' => ***** (string)
5959
| 'PASSWORD' => ***** (string)
6060
| 'Pin' => ***** (string)
61-
| 'bar' => ***** (integer)
61+
| 'bar' => ***** (int)
6262
XX;
6363
Assert::match($expect2, Dumper::toText($obj, [Dumper::SCRUBBER => $scrubber, Dumper::KEYS_TO_HIDE => ['password']]));
6464

tests/Tracy/Dumper.toHtml().key.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Assert::match(
1515
);
1616

1717
Assert::match(
18-
'<pre class="tracy-dump tracy-light"><span class="tracy-dump-virtual">***** (integer)</span></pre>',
18+
'<pre class="tracy-dump tracy-light"><span class="tracy-dump-virtual">***** (int)</span></pre>',
1919
Dumper::toHtml(123, [Dumper::KEYS_TO_HIDE => ['password', 'pin']], 'password'),
2020
);

tools/create-phar/create-phar.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function compressCss(string $s): string
4747
echo "adding: {$iterator->getSubPathname()}\n";
4848

4949
$s = file_get_contents($file->getPathname());
50-
if (strpos($s, '@tracySkipLocation') === false) {
50+
if (!str_contains($s, '@tracySkipLocation')) {
5151
$s = php_strip_whitespace($file->getPathname());
5252
}
5353

@@ -61,7 +61,7 @@ function compressCss(string $s): string
6161
$s = preg_replace_callback('#(<(script|style).*(?<![?=])>)(.*)(</)#Uis', function ($m): string {
6262
[, $begin, $type, $s, $end] = $m;
6363

64-
if ($s === '' || strpos($s, '<?') !== false) {
64+
if ($s === '' || str_contains($s, '<?')) {
6565
return $m[0];
6666

6767
} elseif ($type === 'script') {

0 commit comments

Comments
 (0)