Visitar URL original
Merge pull request #19050 from kamil-tekiela/Errors · phpmyadmin/phpmyadmin@a28cd35 · GitHub
Skip to content

Commit a28cd35

Browse files
Merge pull request #19050 from kamil-tekiela/Errors
Refactor errors
2 parents 6eb5253 + 2f7161f commit a28cd35

13 files changed

Lines changed: 91 additions & 104 deletions

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,6 @@ parameters:
585585
count: 1
586586
path: src/Config/Form.php
587587

588-
-
589-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
590-
count: 2
591-
path: src/Config/Form.php
592-
593588
-
594589
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
595590
count: 2
@@ -7340,11 +7335,6 @@ parameters:
73407335
count: 1
73417336
path: src/Error/Error.php
73427337

7343-
-
7344-
message: "#^Match expression does not handle remaining values\\: 3\\|int\\<min, \\-1\\>\\|int\\<5, 7\\>\\|int\\<9, 15\\>\\|int\\<17, 31\\>\\|int\\<33, 63\\>\\|int\\<65, 127\\>\\|int\\<129, 255\\>\\|int\\<257, 511\\>\\|int\\<513, 1023\\>\\|int\\<1025, 2047\\>\\|int\\<2049, 4095\\>\\|int\\<4097, 8191\\>\\|int\\<8193, 16383\\>\\|int\\<16385, max\\>$#"
7345-
count: 2
7346-
path: src/Error/Error.php
7347-
73487338
-
73497339
message: "#^Only booleans are allowed in \\|\\|, int\\<0, 18176\\> given on the right side\\.$#"
73507340
count: 1
@@ -14385,11 +14375,6 @@ parameters:
1438514375
count: 1
1438614376
path: src/Theme/Theme.php
1438714377

14388-
-
14389-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
14390-
count: 1
14391-
path: src/Theme/Theme.php
14392-
1439314378
-
1439414379
message: "#^Left side of && is always true\\.$#"
1439514380
count: 1
@@ -14415,11 +14400,6 @@ parameters:
1441514400
count: 1
1441614401
path: src/Theme/ThemeManager.php
1441714402

14418-
-
14419-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
14420-
count: 1
14421-
path: src/Theme/ThemeManager.php
14422-
1442314403
-
1442414404
message: "#^Cannot access offset string on mixed\\.$#"
1442514405
count: 2

‎psalm-baseline.xml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,6 @@
399399
<ReferenceReusedFromConfusingScope>
400400
<code><![CDATA[$name]]></code>
401401
</ReferenceReusedFromConfusingScope>
402-
<UnevaluatedCode>
403-
<code><![CDATA[return [];]]></code>
404-
<code><![CDATA[return [];]]></code>
405-
</UnevaluatedCode>
406402
</file>
407403
<file src="src/Config/FormDisplay.php">
408404
<DeprecatedMethod>
@@ -11269,9 +11265,6 @@
1126911265
<PossiblyUnusedProperty>
1127011266
<code><![CDATA[$filesizeInfo]]></code>
1127111267
</PossiblyUnusedProperty>
11272-
<UnevaluatedCode>
11273-
<code><![CDATA[return false;]]></code>
11274-
</UnevaluatedCode>
1127511268
</file>
1127611269
<file src="src/Theme/ThemeManager.php">
1127711270
<DeprecatedMethod>
@@ -11306,9 +11299,6 @@
1130611299
<RiskyTruthyFalsyComparison>
1130711300
<code><![CDATA[$cookieTheme]]></code>
1130811301
</RiskyTruthyFalsyComparison>
11309-
<UnevaluatedCode>
11310-
<code><![CDATA[return false;]]></code>
11311-
</UnevaluatedCode>
1131211302
</file>
1131311303
<file src="src/Tracking/Tracker.php">
1131411304
<DeprecatedMethod>

‎src/Config/Form.php‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace PhpMyAdmin\Config;
99

10+
use PhpMyAdmin\Exceptions\UndefinedOption;
11+
use Webmozart\Assert\Assert;
12+
1013
use function array_combine;
1114
use function array_shift;
1215
use function array_walk;
@@ -21,9 +24,6 @@
2124
use function mb_substr;
2225
use function str_replace;
2326
use function str_starts_with;
24-
use function trigger_error;
25-
26-
use const E_USER_ERROR;
2727

2828
/**
2929
* Base class for forms, loads default configuration options, checks allowed
@@ -110,16 +110,10 @@ public function getOptionValueList(string $optionPath): array
110110
{
111111
$value = $this->configFile->getDbEntry($optionPath);
112112
if ($value === null) {
113-
trigger_error($optionPath . ' - select options not defined', E_USER_ERROR);
114-
115-
return [];
113+
throw new UndefinedOption($optionPath . ' - select options not defined');
116114
}
117115

118-
if (! is_array($value)) {
119-
trigger_error($optionPath . ' - not a static value list', E_USER_ERROR);
120-
121-
return [];
122-
}
116+
Assert::isArray($value, $optionPath . ' - not a static value list');
123117

124118
// convert array('#', 'a', 'b') to array('a', 'b')
125119
if (isset($value[0]) && $value[0] === '#') {

‎src/Error/Error.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function getLine(): int
258258
public function getType(): string
259259
{
260260
return match ($this->errorNumber) {
261-
0 => 'Internal error',
261+
default => 'Internal error',
262262
E_ERROR => 'Error',
263263
E_WARNING => 'Warning',
264264
E_PARSE => 'Parsing Error',
@@ -285,7 +285,7 @@ public function getType(): string
285285
public function getLevel(): string
286286
{
287287
return match ($this->errorNumber) {
288-
0 => 'error',
288+
default => 'error',
289289
E_ERROR => 'error',
290290
E_WARNING => 'error',
291291
E_PARSE => 'error',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Exceptions;
6+
7+
use Exception;
8+
9+
class InvalidImagePath extends Exception
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Exceptions;
6+
7+
use Exception;
8+
9+
class MismatchedSessionId extends Exception
10+
{
11+
}

‎src/Exceptions/MissingTheme.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Exceptions;
6+
7+
use Exception;
8+
9+
class MissingTheme extends Exception
10+
{
11+
}

‎src/Exceptions/UndefinedOption.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Exceptions;
6+
7+
use RuntimeException;
8+
9+
class UndefinedOption extends RuntimeException
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Exceptions;
6+
7+
use Exception;
8+
9+
class UnsupportedLanguageCode extends Exception
10+
{
11+
}

‎src/Http/Middleware/TokenRequestParamChecking.php‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Http\Middleware;
66

7+
use PhpMyAdmin\Exceptions\MismatchedSessionId;
78
use PhpMyAdmin\Sanitize;
89
use Psr\Http\Message\ResponseInterface;
910
use Psr\Http\Message\ServerRequestInterface;
@@ -14,9 +15,6 @@
1415
use function hash_equals;
1516
use function is_scalar;
1617
use function session_id;
17-
use function trigger_error;
18-
19-
use const E_USER_ERROR;
2018

2119
/**
2220
* Check whether user supplied token is valid, if not remove any possibly
@@ -55,11 +53,10 @@ public function checkTokenRequestParam(): void
5553

5654
// Warn in case the mismatch is result of failed setting of session cookie
5755
if (isset($_POST['set_session']) && $_POST['set_session'] !== session_id()) {
58-
trigger_error(
56+
throw new MismatchedSessionId(
5957
__(
6058
'Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.',
6159
),
62-
E_USER_ERROR,
6360
);
6461
}
6562

0 commit comments

Comments
 (0)