From 4acd79bd83e3422187516cb1c3443eac48cf5dcc Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 16 Mar 2026 20:06:18 +0000 Subject: [PATCH] Fix some issues Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 62 +++++++------------ psalm-baseline.xml | 41 ++---------- .../Server/DatabasesController.php | 4 +- src/Plugins/Import/ImportSql.php | 15 ++--- src/Replication/ReplicationInfo.php | 6 +- src/Server/Privileges.php | 30 ++++----- src/ZipExtension.php | 2 +- 7 files changed, 53 insertions(+), 107 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index eea85f2503..484562b0bf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2259,6 +2259,18 @@ parameters: count: 1 path: src/Controllers/Server/DatabasesController.php + - + message: '#^Offset ''Do_DB'' might not exist on array\{status\: true, Do_DB\?\: array\, Ignore_DB\?\: array\\}\.$#' + identifier: offsetAccess.notFound + count: 2 + path: src/Controllers/Server/DatabasesController.php + + - + message: '#^Offset ''Ignore_DB'' might not exist on array\{status\: true, Do_DB\?\: array\, Ignore_DB\?\: array\\}\.$#' + identifier: offsetAccess.notFound + count: 1 + path: src/Controllers/Server/DatabasesController.php + - message: '#^Parameter \#1 \$params of static method PhpMyAdmin\\Url\:\:getCommonRaw\(\) expects array\, array\ given\.$#' identifier: argument.type @@ -2274,13 +2286,13 @@ parameters: - message: '#^Parameter \#1 \$value of function count expects array\|Countable, mixed given\.$#' identifier: argument.type - count: 2 + count: 1 path: src/Controllers/Server/DatabasesController.php - message: '#^Parameter \#2 \$haystack of function array_search expects array, mixed given\.$#' identifier: argument.type - count: 4 + count: 2 path: src/Controllers/Server/DatabasesController.php - @@ -2331,12 +2343,6 @@ parameters: count: 1 path: src/Controllers/Server/PrivilegesController.php - - - message: '#^Only booleans are allowed in an if condition, mixed given\.$#' - identifier: if.condNotBoolean - count: 1 - path: src/Controllers/Server/ReplicationController.php - - message: '#^Parameter \#2 \$serverReplicaStatus of method PhpMyAdmin\\Replication\\ReplicationGui\:\:getHtmlForReplicaConfiguration\(\) expects bool, mixed given\.$#' identifier: argument.type @@ -2436,7 +2442,7 @@ parameters: - message: '#^Only booleans are allowed in an if condition, mixed given\.$#' identifier: if.condNotBoolean - count: 2 + count: 1 path: src/Controllers/Server/Status/StatusController.php - @@ -9366,6 +9372,12 @@ parameters: count: 1 path: src/Plugins/Import/ImportSql.php + - + message: '#^Parameter \#1 \$sqlCompatibility of method PhpMyAdmin\\Plugins\\Import\\ImportSql\:\:setSQLMode\(\) expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Plugins/Import/ImportSql.php + - message: '#^Argument of an invalid type SimpleXMLElement\|null supplied for foreach, only iterables are supported\.$#' identifier: foreach.nonIterable @@ -10992,12 +11004,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: '#^Cannot access offset 0 on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Server/Privileges.php - - message: '#^Cannot cast array\\|string\|null to string\.$#' identifier: cast.string @@ -11136,18 +11142,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: '#^Parameter \#1 \$query of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:query\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Server/Privileges.php - - - - message: '#^Parameter \#1 \$query of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:tryQuery\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Server/Privileges.php - - message: '#^Parameter \#1 \$row of method PhpMyAdmin\\Server\\Privileges\:\:extractPrivInfo\(\) expects array\\|null, mixed given\.$#' identifier: argument.type @@ -11334,7 +11328,7 @@ parameters: - message: '#^Only booleans are allowed in an if condition, mixed given\.$#' identifier: if.condNotBoolean - count: 2 + count: 1 path: src/Server/Status/Data.php - @@ -13440,18 +13434,6 @@ parameters: count: 1 path: src/ZipExtension.php - - - message: '#^Parameter \#1 \$keys of function array_combine expects array\, array\ given\.$#' - identifier: argument.type - count: 1 - path: src/ZipExtension.php - - - - message: '#^Parameter \#3 \$subject of function str_replace expects array\\|string, \(int\|string\) given\.$#' - identifier: argument.type - count: 1 - path: src/ZipExtension.php - - message: '#^Cannot access offset ''Console'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 399bb57af5..f1283808f5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1589,9 +1589,6 @@ - - - @@ -1622,9 +1619,11 @@ - - + + + + @@ -1675,9 +1674,6 @@ - - - @@ -6284,14 +6280,9 @@ - - - - - - + @@ -7272,12 +7263,7 @@ - - - - - @@ -7288,8 +7274,6 @@ - - @@ -7302,10 +7286,7 @@ - - - @@ -8605,18 +8586,6 @@ - - - - - - - - - - - - diff --git a/src/Controllers/Server/DatabasesController.php b/src/Controllers/Server/DatabasesController.php index 904afe98eb..d949fd2f7d 100644 --- a/src/Controllers/Server/DatabasesController.php +++ b/src/Controllers/Server/DatabasesController.php @@ -174,8 +174,8 @@ final class DatabasesController implements InvocableController } /** - * @param mixed[] $primaryInfo - * @param mixed[] $replicaInfo + * @param array{status: bool, Do_DB?: string[], Ignore_DB?: string[]} $primaryInfo + * @param mixed[] $replicaInfo * * @return array{databases:mixed[], total_statistics:mixed[]} */ diff --git a/src/Plugins/Import/ImportSql.php b/src/Plugins/Import/ImportSql.php index 8cc590dea1..c4711a9d0e 100644 --- a/src/Plugins/Import/ImportSql.php +++ b/src/Plugins/Import/ImportSql.php @@ -95,7 +95,7 @@ class ImportSql extends ImportPlugin public function doImport(File|null $importHandle = null): array { // Handle compatibility options. - $this->setSQLMode($_REQUEST); + $this->setSQLMode($_REQUEST['sql_compatibility'] ?? null, isset($_REQUEST['sql_no_auto_value_on_zero'])); $bq = new BufferedQuery(); if (isset($_POST['sql_delimiter'])) { @@ -164,19 +164,14 @@ class ImportSql extends ImportPlugin return $sqlStatements; } - /** - * Handle compatibility options - * - * @param mixed[] $request Request array - */ - private function setSQLMode(array $request): void + private function setSQLMode(string|null $sqlCompatibility, bool $sqlNoAutoValueOnZero): void { $sqlModes = []; - if (isset($request['sql_compatibility']) && $request['sql_compatibility'] !== 'NONE') { - $sqlModes[] = $request['sql_compatibility']; + if ($sqlCompatibility !== null && $sqlCompatibility !== 'NONE') { + $sqlModes[] = $sqlCompatibility; } - if (isset($request['sql_no_auto_value_on_zero'])) { + if ($sqlNoAutoValueOnZero) { $sqlModes[] = 'NO_AUTO_VALUE_ON_ZERO'; } diff --git a/src/Replication/ReplicationInfo.php b/src/Replication/ReplicationInfo.php index 0a2b433009..66fa2c07ef 100644 --- a/src/Replication/ReplicationInfo.php +++ b/src/Replication/ReplicationInfo.php @@ -79,8 +79,8 @@ final class ReplicationInfo /** @var mixed[] */ private array $multiPrimaryStatus = []; - /** @var mixed[] */ - private array $primaryInfo = []; + /** @var array{status: bool, Do_DB?: string[], Ignore_DB?: string[]} */ + private array $primaryInfo = ['status' => false]; /** @var mixed[] */ private array $replicaInfo = []; @@ -177,7 +177,7 @@ final class ReplicationInfo $this->primaryInfo['Ignore_DB'] = $this->fill($this->primaryStatus, 'Binlog_Ignore_DB'); } - /** @return mixed[] */ + /** @return array{status: bool, Do_DB?: string[], Ignore_DB?: string[]} */ public function getPrimaryInfo(): array { return $this->primaryInfo; diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index cc483d4aa6..c5d26ca03c 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -1869,7 +1869,7 @@ class Privileges /** * Delete user and get message and sql query for delete user in privileges * - * @param mixed[] $queries queries + * @param string[] $queries queries * * @return array{string, Message} Message */ @@ -2106,9 +2106,9 @@ class Privileges /** * Update Data for information: Deletes users * - * @param mixed[] $queries queries array + * @param string[] $queries queries array * - * @return mixed[] + * @return string[] */ public function getDataForDeleteUsers(array $queries, bool $isChangeCopyUser): array { @@ -2173,10 +2173,10 @@ class Privileges /** * update Data For Queries from queries_for_display * - * @param mixed[] $queries queries array - * @param mixed[]|null $queriesForDisplay queries array for display + * @param string[] $queries queries array + * @param string[]|null $queriesForDisplay queries array for display * - * @return mixed[] + * @return string[] */ public function getDataForQueries(array $queries, array|null $queriesForDisplay): array { @@ -2626,12 +2626,12 @@ class Privileges /** * Get queries for Table privileges to change or copy user * - * @param string $userHostCondition user host condition to select relevant table privileges - * @param mixed[] $queries queries array - * @param string $username username - * @param string $hostname host name + * @param string $userHostCondition user host condition to select relevant table privileges + * @param string[] $queries queries array + * @param string $username username + * @param string $hostname host name * - * @return mixed[] + * @return string[] */ public function getTablePrivsQueriesForChangeOrCopyUser( string $userHostCondition, @@ -2708,11 +2708,11 @@ class Privileges /** * Get queries for database specific privileges for change or copy user * - * @param mixed[] $queries queries array with string - * @param string $username username - * @param string $hostname host name + * @param string[] $queries queries array with string + * @param string $username username + * @param string $hostname host name * - * @return mixed[] + * @return string[] */ public function getDbSpecificPrivsQueriesForChangeOrCopyUser( array $queries, diff --git a/src/ZipExtension.php b/src/ZipExtension.php index e33ed94b8a..7ecd1a38a6 100644 --- a/src/ZipExtension.php +++ b/src/ZipExtension.php @@ -195,7 +195,7 @@ class ZipExtension * same amount of elements. * * @param string[]|string $data contents of the file/files - * @param mixed[]|string $name name of the file/files in the archive + * @param string[]|string $name name of the file/files in the archive * * @return string|false the ZIP file contents, or false if there was an error. */