Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 2 additions & 56 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5880,45 +5880,15 @@ parameters:
-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 3
path: src/Error/Error.php

-
message: '#^Binary operation "\." between mixed and ''\('' results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Error/Error.php

-
message: '#^Binary operation "\." between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Error/Error.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Error/Error.php

-
message: '#^Binary operation "\.\=" between non\-falsy\-string and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 2
path: src/Error/Error.php

-
message: '#^Cannot access offset ''args'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Error/Error.php

-
message: '#^Cannot access offset ''class'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Error/Error.php

-
message: '#^Cannot access offset ''class''\|''function''\|''line''\|''type'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
Expand All @@ -5928,23 +5898,11 @@ parameters:
-
message: '#^Cannot access offset ''file'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/Error/Error.php

-
message: '#^Cannot access offset ''function'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Error/Error.php

-
message: '#^Cannot access offset ''line'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Error/Error.php

-
message: '#^Cannot access offset ''type'' on mixed\.$#'
message: '#^Cannot access offset ''function'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Error/Error.php
Expand All @@ -5964,21 +5922,9 @@ parameters:
-
message: '#^Parameter \#1 \$path of static method PhpMyAdmin\\Error\\Error\:\:relPath\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Error/Error.php

-
message: '#^Parameter \#1 \$step of static method PhpMyAdmin\\Error\\Error\:\:getFunctionCall\(\) expects array\<mixed\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Error/Error.php

-
message: '#^Parameter \#1 \$value of function count expects array\|Countable, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Error/Error.php

-
message: '#^Parameter \#2 \$function of static method PhpMyAdmin\\Error\\Error\:\:getArg\(\) expects string, mixed given\.$#'
identifier: argument.type
Expand All @@ -5997,7 +5943,7 @@ parameters:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
count: 6
count: 5
path: src/Error/ErrorHandler.php

-
Expand Down
19 changes: 0 additions & 19 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4029,42 +4029,24 @@
</file>
<file src="src/Error/Error.php">
<MixedArgument>
<code><![CDATA[$step]]></code>
<code><![CDATA[$step['args']]]></code>
<code><![CDATA[$step['args']]]></code>
<code><![CDATA[$step['file']]]></code>
<code><![CDATA[$step['file']]]></code>
<code><![CDATA[$step['function']]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$step[$name]]]></code>
<code><![CDATA[$step['args']]]></code>
<code><![CDATA[$step['class']]]></code>
<code><![CDATA[$step['file']]]></code>
<code><![CDATA[$step['file']]]></code>
<code><![CDATA[$step['function']]]></code>
<code><![CDATA[$step['line']]]></code>
<code><![CDATA[$step['type']]]></code>
</MixedArrayAccess>
<MixedArrayOffset>
<code><![CDATA[$result[$idx]['args'][$key]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$key]]></code>
<code><![CDATA[$result[$idx][$name]]]></code>
<code><![CDATA[$step]]></code>
<code><![CDATA[$step]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$step['class']]]></code>
<code><![CDATA[$step['function']]]></code>
<code><![CDATA[$step['line']]]></code>
</MixedOperand>
</file>
<file src="src/Error/ErrorHandler.php">
<DeprecatedMethod>
Expand All @@ -4073,7 +4055,6 @@
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[Config::getInstance()]]></code>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$_SESSION['errors']]]></code>
Expand Down
5 changes: 0 additions & 5 deletions resources/templates/error/get_display.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@
{%- endif -%}

{{ message|raw }}

{%- if not is_user_error and formatted_backtrace is not empty -%}
<p class="mt-3"><strong>Backtrace</strong></p>
{{- formatted_backtrace|raw -}}
{%- endif -%}
</div>
67 changes: 0 additions & 67 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,72 +309,6 @@ public function getTitle(): string
return $this->getType() . ': ' . $this->getMessage();
}

/**
* Get HTML backtrace
*/
public function getBacktraceDisplay(): string
{
return self::formatBacktrace($this->getBacktrace());
}

/**
* return formatted backtrace field
*
* @param mixed[] $backtrace Backtrace data
*
* @return string formatted backtrace
*/
public static function formatBacktrace(array $backtrace): string
{
if ($backtrace === []) {
return '';
}

$retval = '<ol class="list-group">';

foreach ($backtrace as $step) {
$retval .= '<li class="list-group-item">';
if (isset($step['file'], $step['line'])) {
$retval .= self::relPath($step['file']) . '#' . $step['line'] . ': ';
}

if (isset($step['class'])) {
$retval .= $step['class'] . $step['type'];
}

$retval .= self::getFunctionCall($step);
$retval .= '</li>';
}

return $retval . '</ol>';
}

/**
* Formats function call in a backtrace
*
* @param mixed[] $step backtrace step
*/
public static function getFunctionCall(array $step): string
{
$retval = $step['function'] . '(';
if (isset($step['args'])) {
if (count($step['args']) > 1) {
$retval .= '<br>';
foreach ($step['args'] as $arg) {
$retval .= "\t";
$retval .= $arg;
$retval .= ',<br>';
}
} elseif (count($step['args']) > 0) {
foreach ($step['args'] as $arg) {
$retval .= $arg;
}
}
}

return $retval . ')';
}

/**
* Get a single function argument
*
Expand Down Expand Up @@ -431,7 +365,6 @@ public function getDisplay(): string
'file' => $this->getFile(),
'line' => $this->getLine(),
'message' => $this->getMessage(),
'formatted_backtrace' => $this->getBacktraceDisplay(),
]);
}

Expand Down
15 changes: 8 additions & 7 deletions src/Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
use function function_exists;
use function htmlspecialchars;
use function sprintf;
use function str_contains;
use function str_replace;

use const DIRECTORY_SEPARATOR;
use const E_COMPILE_ERROR;
use const E_COMPILE_WARNING;
use const E_CORE_ERROR;
Expand Down Expand Up @@ -224,14 +227,8 @@ public function handleError(
*/
public function handleException(Throwable $exception): void
{
$this->hideLocation = Config::getInstance()->config->environment !== 'development';
$message = $exception::class;
if (! ($exception instanceof \Error) || ! $this->hideLocation) {
$message .= ': ' . $exception->getMessage();
}

$this->addError(
$message,
$exception::class . ': ' . $exception->getMessage(),
(int) $exception->getCode(),
$exception->getFile(),
$exception->getLine(),
Expand Down Expand Up @@ -262,6 +259,10 @@ public function addError(
int $errline,
bool $escape = true,
): void {
if (str_contains($errstr, ROOT_PATH)) {
$errstr = str_replace(ROOT_PATH, '.' . DIRECTORY_SEPARATOR, $errstr);
}

if ($escape) {
$errstr = htmlspecialchars($errstr);
}
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/Error/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function testHandleExceptionForProdEnv(): void
self::assertSame('Exception: Exception message.', $error->getOnlyMessage());
self::assertStringContainsString($error->getDisplay(), $output);
self::assertStringContainsString('Exception: Exception message.', $output);
self::assertStringNotContainsString('ErrorHandlerTest.php#' . $error->getLine(), $output);
self::assertStringContainsString('ErrorHandlerTest.php#' . $error->getLine(), $output);
}

public function testAddErrorWithFatalError(): void
Expand All @@ -318,11 +318,14 @@ public function testAddErrorWithFatalError(): void
<html lang="en">
<head><title>Error: Fatal error message!</title></head>
<body>
<div class="alert alert-danger" role="alert"><p><strong>Error</strong> in name#1</p><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Fatal error message!<p class="mt-3"><strong>Backtrace</strong></p><ol class="list-group"><li class="list-group-item">
<div class="alert alert-danger" role="alert"><p><strong>Error</strong> in name#1</p><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Fatal error message!
</div>

</body>
</html>
HTML;
// phpcs:enable
$output = $this->getActualOutputForAssertion();
self::assertStringStartsWith($expectedStart, $output);
self::assertStringEndsWith('</li></ol></div>' . "\n\n" . '</body>' . "\n" . '</html>', $output);
self::assertSame($expectedStart, $output);
}
}
23 changes: 3 additions & 20 deletions tests/unit/Error/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,18 @@ public function testGetHash(): void
);
}

/**
* Test for getBacktraceDisplay
*/
public function testGetBacktraceDisplay(): void
{
self::assertStringContainsString(
'PHPUnit\Framework\TestRunner->run(<Class:PhpMyAdmin\Tests\Error\ErrorTest>)',
$this->object->getBacktraceDisplay(),
);
}

/**
* Test for getDisplay
*/
public function testGetDisplay(): void
{
$actual = $this->object->getDisplay();
self::assertStringStartsWith(
self::assertSame(
'<div class="alert alert-danger" role="alert"><p><strong>Warning</strong> in error.txt#15</p>'
. '<img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Compile Error'
. '<p class="mt-3"><strong>Backtrace</strong></p><ol class="list-group"><li class="list-group-item">',
$actual,
);
self::assertStringContainsString(
'PHPUnit\Framework\TestRunner->run(<Class:PhpMyAdmin\Tests\Error\ErrorTest>)</li>'
. '<li class="list-group-item">',
. '<img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> Compile Error' . "\n"
. '</div>' . "\n",
$actual,
);
self::assertStringEndsWith('</li></ol></div>' . "\n", $actual);
}

#[DataProvider('errorLevelProvider')]
Expand Down
Loading