Skip to content

Commit

Permalink
Merge pull request phpmyadmin#19025 from kamil-tekiela/intval
Browse files Browse the repository at this point in the history
Replace function casts with normal casts
  • Loading branch information
MauricioFauth authored Mar 4, 2024
2 parents 856d316 + 54b5464 commit 1eefe72
Show file tree
Hide file tree
Showing 35 changed files with 152 additions and 143 deletions.
107 changes: 66 additions & 41 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ parameters:

-
message: "#^Cannot cast mixed to int\\.$#"
count: 3
count: 4
path: src/Controllers/Import/ImportController.php

-
Expand Down Expand Up @@ -2690,11 +2690,6 @@ parameters:
count: 1
path: src/Controllers/Import/ImportController.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Import/ImportController.php

-
message: "#^Parameter \\#11 \\$sqlQuery of method PhpMyAdmin\\\\Sql\\:\\:executeQueryAndGetQueryResponse\\(\\) expects string, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -2856,7 +2851,7 @@ parameters:
path: src/Controllers/NavigationController.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Controllers/Normalization/CreateNewColumnController.php

Expand Down Expand Up @@ -3861,7 +3856,7 @@ parameters:
path: src/Controllers/Setup/ValidateController.php

-
message: "#^Parameter \\#1 \\$value of function strval expects bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot cast mixed to string\\.$#"
count: 2
path: src/Controllers/Sql/EnumValuesController.php

Expand All @@ -3871,7 +3866,7 @@ parameters:
path: src/Controllers/Sql/RelationalValuesController.php

-
message: "#^Parameter \\#1 \\$value of function strval expects bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot cast mixed to string\\.$#"
count: 2
path: src/Controllers/Sql/RelationalValuesController.php

Expand Down Expand Up @@ -4221,20 +4216,15 @@ parameters:
path: src/Controllers/Table/CreateController.php

-
message: "#^Only booleans are allowed in an if condition, PhpMyAdmin\\\\Dbal\\\\ResultInterface\\|false given\\.$#"
count: 1
message: "#^Cannot cast mixed to int\\.$#"
count: 5
path: src/Controllers/Table/CreateController.php

-
message: "#^Parameter \\#1 \\$string of function strlen expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Table/CreateController.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 5
path: src/Controllers/Table/CreateController.php

-
message: "#^Parameter \\#3 \\$key of method PhpMyAdmin\\\\Transformations\\:\\:setMime\\(\\) expects string, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -4970,6 +4960,11 @@ parameters:
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Controllers/Table/SearchController.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
Expand Down Expand Up @@ -5580,11 +5575,21 @@ parameters:
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
Expand Down Expand Up @@ -5655,11 +5660,6 @@ parameters:
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Table/ZoomSearchController.php

-
message: "#^Parameter \\#2 \\$columnIndex of method PhpMyAdmin\\\\Controllers\\\\Table\\\\ZoomSearchController\\:\\:getColumnProperties\\(\\) expects int, int\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -6380,6 +6380,11 @@ parameters:
count: 7
path: src/Database/Events.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Database/Events.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 13
Expand Down Expand Up @@ -6420,11 +6425,6 @@ parameters:
count: 1
path: src/Database/Events.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Database/Events.php

-
message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -7042,6 +7042,11 @@ parameters:

-
message: "#^Cannot cast mixed to int\\.$#"
count: 6
path: src/Display/Results.php

-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Display/Results.php

Expand Down Expand Up @@ -7175,11 +7180,6 @@ parameters:
count: 2
path: src/Display/Results.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 5
path: src/Display/Results.php

-
message: "#^Parameter \\#1 \\$value of static method PhpMyAdmin\\\\Util\\:\\:formatNumber\\(\\) expects float\\|int\\|string, int\\|string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -9595,6 +9595,11 @@ parameters:
count: 1
path: src/Normalization.php

-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Normalization.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 1
Expand Down Expand Up @@ -10140,6 +10145,11 @@ parameters:
count: 1
path: src/Plugins/Auth/AuthenticationCookie.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Plugins/Auth/AuthenticationCookie.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
Expand Down Expand Up @@ -10200,11 +10210,6 @@ parameters:
count: 1
path: src/Plugins/Auth/AuthenticationCookie.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Plugins/Auth/AuthenticationCookie.php

-
message: "#^Parameter \\#2 \\$remoteIp of method ReCaptcha\\\\ReCaptcha\\:\\:verify\\(\\) expects string\\|null, bool\\|string given\\.$#"
count: 1
Expand Down Expand Up @@ -10315,23 +10320,28 @@ parameters:
count: 1
path: src/Plugins/AuthenticationPlugin.php

-
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Plugins/AuthenticationPlugin.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: src/Plugins/AuthenticationPlugin.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Plugins/AuthenticationPlugin.php

-
message: "#^Parameter \\#1 \\$url of method PhpMyAdmin\\\\ResponseRenderer\\:\\:redirect\\(\\) expects non\\-empty\\-string, string given\\.$#"
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/Plugins/AuthenticationPlugin.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Parameter \\#1 \\$url of method PhpMyAdmin\\\\ResponseRenderer\\:\\:redirect\\(\\) expects non\\-empty\\-string, string given\\.$#"
count: 1
path: src/Plugins/AuthenticationPlugin.php

Expand Down Expand Up @@ -12311,7 +12321,7 @@ parameters:
path: src/Plugins/Transformations/Abs/ExternalTransformationsPlugin.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot cast mixed to int\\.$#"
count: 1
path: src/Plugins/Transformations/Abs/HexTransformationsPlugin.php

Expand All @@ -12321,7 +12331,7 @@ parameters:
path: src/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot cast mixed to int\\.$#"
count: 2
path: src/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php

Expand Down Expand Up @@ -13500,6 +13510,16 @@ parameters:
count: 1
path: src/Server/Status/Processes.php

-
message: "#^Method PhpMyAdmin\\\\Server\\\\SysInfo\\\\Linux\\:\\:memory\\(\\) should return array\\<string, int\\> but returns array\\<int\\>\\.$#"
count: 1
path: src/Server/SysInfo/Linux.php

-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(array\\|bool\\|float\\|int\\|resource\\|string\\|null, int\\=\\)\\: int given\\.$#"
count: 1
path: src/Server/SysInfo/Linux.php

-
message: "#^Parameter \\#1 \\$keys of function array_combine expects array\\<int\\|string\\>, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -13975,6 +13995,11 @@ parameters:
count: 2
path: src/Table/ColumnsDefinition.php

-
message: "#^Casting to int something that's already int\\<1, max\\>\\.$#"
count: 1
path: src/Table/ColumnsDefinition.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
Expand Down
38 changes: 30 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2924,20 +2924,12 @@
</UnusedParam>
</file>
<file src="src/Controllers/Sql/EnumValuesController.php">
<MixedArgument>
<code><![CDATA[$column]]></code>
<code><![CDATA[$currValue]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$column]]></code>
<code><![CDATA[$currValue]]></code>
</MixedAssignment>
</file>
<file src="src/Controllers/Sql/RelationalValuesController.php">
<MixedArgument>
<code><![CDATA[$column]]></code>
<code><![CDATA[$currValue]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$_SESSION['tmpval']['relational_display']]]></code>
</MixedArrayAccess>
Expand Down Expand Up @@ -3653,6 +3645,9 @@
<PossiblyUnusedMethod>
<code><![CDATA[getColumnProperties]]></code>
</PossiblyUnusedMethod>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) $config->settings['MaxRows']]]></code>
</RedundantCastGivenDocblockType>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$searchColumnInForeigners]]></code>
<code><![CDATA[empty($row->collation)]]></code>
Expand Down Expand Up @@ -4032,6 +4027,12 @@
<code><![CDATA[$_POST['maxPlotLimit']]]></code>
<code><![CDATA[$_POST['where_clause']]]></code>
</PossiblyInvalidOperand>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) $config->settings['maxRowPlotLimit']]]></code>
</RedundantCastGivenDocblockType>
<RiskyCast>
<code><![CDATA[$_POST['maxPlotLimit']]]></code>
</RiskyCast>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$searchColumnInForeigners]]></code>
<code><![CDATA[empty($_POST['maxPlotLimit'])]]></code>
Expand Down Expand Up @@ -4642,6 +4643,9 @@
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$GLOBALS['errors']]]></code>
</PossiblyUndefinedArrayOffset>
<RiskyCast>
<code><![CDATA[$_POST['item_interval_value']]]></code>
</RiskyCast>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($_POST['editor_process_edit'])]]></code>
<code><![CDATA[empty($_POST['item_comment'])]]></code>
Expand Down Expand Up @@ -5350,6 +5354,9 @@
<code><![CDATA[$o->expr->expr]]></code>
<code><![CDATA[$order->expr->column]]></code>
</PossiblyNullPropertyFetch>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) $this->config->settings['MaxRows']]]></code>
</RedundantCastGivenDocblockType>
<RedundantCondition>
<code><![CDATA[! empty($added[$orgFullTableName])]]></code>
<code><![CDATA[empty($statementInfo->statement->from)]]></code>
Expand Down Expand Up @@ -7098,6 +7105,9 @@
<RedundantCast>
<code><![CDATA[(string) $dependon]]></code>
</RedundantCast>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) $this->config->settings['MaxRows']]]></code>
</RedundantCastGivenDocblockType>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$dropCols]]></code>
</RiskyTruthyFalsyComparison>
Expand Down Expand Up @@ -7554,6 +7564,9 @@
<RedundantCast>
<code><![CDATA[(string) $GLOBALS['conn_error']]]></code>
</RedundantCast>
<RiskyCast>
<code><![CDATA[$_GET['session_expired']]]></code>
</RiskyCast>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['conn_error'])]]></code>
<code><![CDATA[empty($_POST[$config->settings['CaptchaResponseParam']])]]></code>
Expand Down Expand Up @@ -7640,6 +7653,12 @@
<PossiblyInvalidCast>
<code><![CDATA[$_REQUEST['guid']]]></code>
</PossiblyInvalidCast>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) Config::getInstance()->settings['LoginCookieValidity']]]></code>
</RedundantCastGivenDocblockType>
<RiskyCast>
<code><![CDATA[$_REQUEST['access_time']]]></code>
</RiskyCast>
</file>
<file src="src/Plugins/AuthenticationPluginFactory.php">
<DeprecatedMethod>
Expand Down Expand Up @@ -10987,6 +11006,9 @@
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$columnMeta['DefaultValue']]]></code>
</PossiblyUndefinedArrayOffset>
<RedundantCastGivenDocblockType>
<code><![CDATA[(int) $config->settings['MaxRows']]]></code>
</RedundantCastGivenDocblockType>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! $columnMeta['column_status']['isEditable']]]></code>
<code><![CDATA[! $columnMeta['column_status']['isEditable']]]></code>
Expand Down
Loading

0 comments on commit 1eefe72

Please sign in to comment.