Skip to content

Commit dee8efe

Browse files
Merge pull request #18905 from kamil-tekiela/Remove-mb_str-functions
Remove mb_str* functions when used in bool context
2 parents d689cca + 5ce27be commit dee8efe

28 files changed

+119
-208
lines changed

phpstan-baseline.neon

Lines changed: 20 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,14 @@ parameters:
462462

463463
-
464464
message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#"
465-
count: 3
465+
count: 2
466466
path: src/Config.php
467467

468468
-
469469
message: "#^Only booleans are allowed in an elseif condition, int\\|false given\\.$#"
470470
count: 6
471471
path: src/Config.php
472472

473-
-
474-
message: "#^Only booleans are allowed in an elseif condition, string\\|false given\\.$#"
475-
count: 4
476-
path: src/Config.php
477-
478473
-
479474
message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#"
480475
count: 1
@@ -487,7 +482,7 @@ parameters:
487482

488483
-
489484
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
490-
count: 4
485+
count: 2
491486
path: src/Config.php
492487

493488
-
@@ -511,7 +506,7 @@ parameters:
511506
path: src/Config.php
512507

513508
-
514-
message: "#^Parameter \\#1 \\$haystack of function mb_strstr expects string, mixed given\\.$#"
509+
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, mixed given\\.$#"
515510
count: 1
516511
path: src/Config.php
517512

@@ -1090,6 +1085,11 @@ parameters:
10901085
count: 1
10911086
path: src/Config/Validator.php
10921087

1088+
-
1089+
message: "#^Parameter \\#1 \\$haystack of function str_starts_with expects string, mixed given\\.$#"
1090+
count: 1
1091+
path: src/Config/Validator.php
1092+
10931093
-
10941094
message: "#^Parameter \\#1 \\$host of static method PhpMyAdmin\\\\Config\\\\Validator\\:\\:testDBConnection\\(\\) expects string, mixed given\\.$#"
10951095
count: 2
@@ -1107,7 +1107,7 @@ parameters:
11071107

11081108
-
11091109
message: "#^Parameter \\#1 \\$string of function mb_substr expects string, mixed given\\.$#"
1110-
count: 2
1110+
count: 1
11111111
path: src/Config/Validator.php
11121112

11131113
-
@@ -7745,14 +7745,9 @@ parameters:
77457745
count: 2
77467746
path: src/Display/Results.php
77477747

7748-
-
7749-
message: "#^Parameter \\#1 \\$haystack of function mb_strpos expects string, mixed given\\.$#"
7750-
count: 2
7751-
path: src/Display/Results.php
7752-
77537748
-
77547749
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, mixed given\\.$#"
7755-
count: 1
7750+
count: 3
77567751
path: src/Display/Results.php
77577752

77587753
-
@@ -8160,11 +8155,6 @@ parameters:
81608155
count: 1
81618156
path: src/Export/Export.php
81628157

8163-
-
8164-
message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\>\\|false given\\.$#"
8165-
count: 2
8166-
path: src/Export/Export.php
8167-
81688158
-
81698159
message: "#^Only booleans are allowed in a negated boolean, int\\|false given\\.$#"
81708160
count: 1
@@ -8235,11 +8225,6 @@ parameters:
82358225
count: 1
82368226
path: src/Export/Options.php
82378227

8238-
-
8239-
message: "#^Only booleans are allowed in an if condition, int\\<0, max\\>\\|false given\\.$#"
8240-
count: 1
8241-
path: src/Export/Options.php
8242-
82438228
-
82448229
message: "#^PHPDoc tag @var for variable \\$dbSelect has no value type specified in iterable type array\\.$#"
82458230
count: 1
@@ -8990,11 +8975,6 @@ parameters:
89908975
count: 1
89918976
path: src/Html/Generator.php
89928977

8993-
-
8994-
message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#"
8995-
count: 1
8996-
path: src/Html/Generator.php
8997-
89988978
-
89998979
message: "#^Only booleans are allowed in an elseif condition, int\\|false given\\.$#"
90008980
count: 1
@@ -9007,7 +8987,7 @@ parameters:
90078987

90088988
-
90098989
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
9010-
count: 3
8990+
count: 1
90118991
path: src/Html/Generator.php
90128992

90138993
-
@@ -9585,11 +9565,6 @@ parameters:
95859565
count: 2
95869566
path: src/InsertEdit.php
95879567

9588-
-
9589-
message: "#^Only booleans are allowed in &&, string\\|false given on the right side\\.$#"
9590-
count: 2
9591-
path: src/InsertEdit.php
9592-
95939568
-
95949569
message: "#^Only booleans are allowed in &&, string\\|null given on the left side\\.$#"
95959570
count: 1
@@ -9610,11 +9585,6 @@ parameters:
96109585
count: 2
96119586
path: src/InsertEdit.php
96129587

9613-
-
9614-
message: "#^Only booleans are allowed in an elseif condition, string\\|false given\\.$#"
9615-
count: 1
9616-
path: src/InsertEdit.php
9617-
96189588
-
96199589
message: "#^Only booleans are allowed in an if condition, array\\<array\\<int\\|string, array\\<array\\<string\\>\\|bool\\|int\\|string\\>\\|bool\\|int\\|string\\|null\\>\\|bool\\|int\\|string\\>\\|bool\\|int\\|string given\\.$#"
96209590
count: 1
@@ -9625,11 +9595,6 @@ parameters:
96259595
count: 1
96269596
path: src/InsertEdit.php
96279597

9628-
-
9629-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
9630-
count: 1
9631-
path: src/InsertEdit.php
9632-
96339598
-
96349599
message: "#^Parameter \\#1 \\$buffer of method PhpMyAdmin\\\\Plugins\\\\TransformationsPlugin\\:\\:applyTransformation\\(\\) expects string, mixed given\\.$#"
96359600
count: 1
@@ -9955,11 +9920,6 @@ parameters:
99559920
count: 1
99569921
path: src/Menu.php
99579922

9958-
-
9959-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
9960-
count: 1
9961-
path: src/Menu.php
9962-
99639923
-
99649924
message: "#^Only numeric types are allowed in \\+, int\\<0, max\\>\\|false given on the left side\\.$#"
99659925
count: 1
@@ -10825,11 +10785,6 @@ parameters:
1082510785
count: 1
1082610786
path: src/Plugins.php
1082710787

10828-
-
10829-
message: "#^Only booleans are allowed in an if condition, int\\<0, max\\>\\|false given\\.$#"
10830-
count: 2
10831-
path: src/Plugins.php
10832-
1083310788
-
1083410789
message: "#^Parameter \\#1 \\$link of static method PhpMyAdmin\\\\Html\\\\MySQLDocumentation\\:\\:show\\(\\) expects string, mixed given\\.$#"
1083510790
count: 2
@@ -11630,11 +11585,6 @@ parameters:
1163011585
count: 7
1163111586
path: src/Plugins/Export/ExportSql.php
1163211587

11633-
-
11634-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
11635-
count: 1
11636-
path: src/Plugins/Export/ExportSql.php
11637-
1163811588
-
1163911589
message: "#^Casting to string something that's already string\\.$#"
1164011590
count: 2
@@ -11655,11 +11605,6 @@ parameters:
1165511605
count: 1
1165611606
path: src/Plugins/Export/ExportSql.php
1165711607

11658-
-
11659-
message: "#^Only booleans are allowed in an elseif condition, int\\<0, max\\>\\|false given\\.$#"
11660-
count: 2
11661-
path: src/Plugins/Export/ExportSql.php
11662-
1166311608
-
1166411609
message: "#^Only booleans are allowed in an elseif condition, mixed given\\.$#"
1166511610
count: 1
@@ -11670,11 +11615,6 @@ parameters:
1167011615
count: 1
1167111616
path: src/Plugins/Export/ExportSql.php
1167211617

11673-
-
11674-
message: "#^Only booleans are allowed in an if condition, int\\<0, max\\>\\|false given\\.$#"
11675-
count: 2
11676-
path: src/Plugins/Export/ExportSql.php
11677-
1167811618
-
1167911619
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
1168011620
count: 1
@@ -11706,7 +11646,7 @@ parameters:
1170611646
path: src/Plugins/Export/ExportSql.php
1170711647

1170811648
-
11709-
message: "#^Parameter \\#1 \\$haystack of function mb_strpos expects string, string\\|null given\\.$#"
11649+
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, string\\|null given\\.$#"
1171011650
count: 3
1171111651
path: src/Plugins/Export/ExportSql.php
1171211652

@@ -14165,6 +14105,11 @@ parameters:
1416514105
count: 2
1416614106
path: src/Server/Privileges.php
1416714107

14108+
-
14109+
message: "#^Parameter \\#1 \\$haystack of function str_starts_with expects string, string\\|null given\\.$#"
14110+
count: 3
14111+
path: src/Server/Privileges.php
14112+
1416814113
-
1416914114
message: "#^Parameter \\#1 \\$name of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:escapeGrantWildcards\\(\\) expects string, array\\<int, string\\>\\|string\\|true\\|null given\\.$#"
1417014115
count: 1
@@ -14220,11 +14165,6 @@ parameters:
1422014165
count: 1
1422114166
path: src/Server/Privileges.php
1422214167

14223-
-
14224-
message: "#^Parameter \\#1 \\$string of function mb_substr expects string, string\\|null given\\.$#"
14225-
count: 3
14226-
path: src/Server/Privileges.php
14227-
1422814168
-
1422914169
message: "#^Parameter \\#1 \\$username of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:getUserHostCondition\\(\\) expects string, mixed given\\.$#"
1423014170
count: 1
@@ -15185,11 +15125,6 @@ parameters:
1518515125
count: 3
1518615126
path: src/Table/Search.php
1518715127

15188-
-
15189-
message: "#^Only booleans are allowed in \\|\\|, int\\<0, max\\>\\|false given on the right side\\.$#"
15190-
count: 1
15191-
path: src/Table/Search.php
15192-
1519315128
-
1519415129
message: "#^Only booleans are allowed in \\|\\|, int\\|false given on the left side\\.$#"
1519515130
count: 1
@@ -15690,11 +15625,6 @@ parameters:
1569015625
count: 2
1569115626
path: src/Tracking/Tracker.php
1569215627

15693-
-
15694-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
15695-
count: 1
15696-
path: src/Tracking/Tracker.php
15697-
1569815628
-
1569915629
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#"
1570015630
count: 2
@@ -15765,16 +15695,6 @@ parameters:
1576515695
count: 1
1576615696
path: src/Tracking/Tracking.php
1576715697

15768-
-
15769-
message: "#^Only booleans are allowed in \\|\\|, string\\|false given on the left side\\.$#"
15770-
count: 1
15771-
path: src/Tracking/Tracking.php
15772-
15773-
-
15774-
message: "#^Only booleans are allowed in \\|\\|, string\\|false given on the right side\\.$#"
15775-
count: 1
15776-
path: src/Tracking/Tracking.php
15777-
1577815698
-
1577915699
message: "#^Only numeric types are allowed in \\-, int\\<0, max\\>\\|false given on the left side\\.$#"
1578015700
count: 2
@@ -16697,16 +16617,16 @@ parameters:
1669716617

1669816618
-
1669916619
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
16700-
count: 3
16620+
count: 1
1670116621
path: tests/classes/ConfigTest.php
1670216622

1670316623
-
16704-
message: "#^Parameter \\#1 \\$haystack of function mb_strstr expects string, array\\<string\\> given\\.$#"
16624+
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, array\\<string\\> given\\.$#"
1670516625
count: 1
1670616626
path: tests/classes/ConfigTest.php
1670716627

1670816628
-
16709-
message: "#^Parameter \\#1 \\$haystack of function mb_strstr expects string, mixed given\\.$#"
16629+
message: "#^Parameter \\#1 \\$haystack of function str_contains expects string, mixed given\\.$#"
1671016630
count: 1
1671116631
path: tests/classes/ConfigTest.php
1671216632

psalm-baseline.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5809,6 +5809,9 @@
58095809
<PossiblyNullArgument>
58105810
<code><![CDATA[$GLOBALS['file_handle']]]></code>
58115811
</PossiblyNullArgument>
5812+
<PossiblyNullArrayAccess>
5813+
<code><![CDATA[$error['message']]]></code>
5814+
</PossiblyNullArrayAccess>
58125815
<RedundantCondition>
58135816
<code>mb_strtolower($userExtension) !== $requiredExtension</code>
58145817
<code>mb_strtolower($userExtension) !== $requiredExtension</code>
@@ -10841,8 +10844,6 @@
1084110844
<code><![CDATA[$dbRights[$row['User']]]]></code>
1084210845
<code>$groupAssignment</code>
1084310846
<code>$row</code>
10844-
<code>$row</code>
10845-
<code>$row</code>
1084610847
</PossiblyNullArrayOffset>
1084710848
<PossiblyNullOperand>
1084810849
<code>$alterUserQuery</code>
@@ -12928,9 +12929,6 @@
1292812929
<code><![CDATA[$config->settings['Server']]]></code>
1292912930
<code><![CDATA[$config->settings['Server']]]></code>
1293012931
</InvalidArrayOffset>
12931-
<InvalidCast>
12932-
<code>$v</code>
12933-
</InvalidCast>
1293412932
<MixedArgument>
1293512933
<code><![CDATA[$gdNfo['GD Version']]]></code>
1293612934
</MixedArgument>
@@ -12946,6 +12944,9 @@
1294612944
<RedundantConditionGivenDocblockType>
1294712945
<code>assertIsArray</code>
1294812946
</RedundantConditionGivenDocblockType>
12947+
<TypeDoesNotContainType>
12948+
<code><![CDATA[str_contains($v, '2.')]]></code>
12949+
</TypeDoesNotContainType>
1294912950
</file>
1295012951
<file src="tests/classes/ConsoleTest.php">
1295112952
<DeprecatedMethod>

src/CheckUserPrivileges.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpMyAdmin\Query\Utilities;
1111
use PhpMyAdmin\Utils\SessionCache;
1212

13-
use function mb_strpos;
1413
use function mb_substr;
1514
use function preg_match;
1615
use function preg_replace;
@@ -38,7 +37,7 @@ public function checkRequiredPrivilegesForAdjust(
3837
if (
3938
$showGrants->grants !== 'ALL'
4039
&& $showGrants->grants !== 'ALL PRIVILEGES'
41-
&& (mb_strpos($showGrants->grants, 'SELECT, INSERT, UPDATE, DELETE') === false)
40+
&& ! str_contains($showGrants->grants, 'SELECT, INSERT, UPDATE, DELETE')
4241
) {
4342
return;
4443
}

0 commit comments

Comments
 (0)