diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3d0045df4b..ee8813feed 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -13612,7 +13612,7 @@ parameters: - message: "#^Cannot access offset 'Host' on mixed\\.$#" - count: 4 + count: 2 path: src/Server/Privileges.php - @@ -13642,7 +13642,7 @@ parameters: - message: "#^Cannot access offset 'User' on mixed\\.$#" - count: 5 + count: 3 path: src/Server/Privileges.php - @@ -13677,12 +13677,12 @@ parameters: - message: "#^Cannot cast mixed to string\\.$#" - count: 8 + count: 6 path: src/Server/Privileges.php - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 18 + count: 15 path: src/Server/Privileges.php - @@ -13797,7 +13797,7 @@ parameters: - message: "#^Parameter \\#1 \\$query of method PhpMyAdmin\\\\DatabaseInterface\\:\\:tryQuery\\(\\) expects string, mixed given\\.$#" - count: 3 + count: 1 path: src/Server/Privileges.php - @@ -13805,11 +13805,6 @@ parameters: count: 2 path: src/Server/Privileges.php - - - message: "#^Parameter \\#1 \\$row of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:getSpecificPrivilege\\(\\) expects array, mixed given\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#" count: 4 @@ -13845,11 +13840,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: "#^Parameter \\#2 \\$realSqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#" count: 6 @@ -13875,11 +13865,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: "#^Parameter \\#3 \\$sqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, mixed given\\.$#" count: 2 @@ -13910,16 +13895,6 @@ parameters: count: 2 path: src/Server/Privileges.php - - - message: "#^Parameter \\#7 \\$alterRealSqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Server/Privileges.php - - - - message: "#^Parameter \\#8 \\$alterSqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Possibly invalid array key type array\\\\|string\\|null\\.$#" count: 1 @@ -17167,7 +17142,7 @@ parameters: - message: "#^Cannot call method getMessage\\(\\) on mixed\\.$#" - count: 6 + count: 2 path: tests/classes/Server/PrivilegesTest.php - @@ -17175,16 +17150,6 @@ parameters: count: 1 path: tests/classes/Server/PrivilegesTest.php - - - message: "#^Parameter \\#2 \\$realSqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: tests/classes/Server/PrivilegesTest.php - - - - message: "#^Parameter \\#3 \\$sqlQuery of method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:addUserAndCreateDatabase\\(\\) expects string, mixed given\\.$#" - count: 1 - path: tests/classes/Server/PrivilegesTest.php - - message: "#^Cannot access offset 'host' on mixed\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5423aef6da..b6aa094a5d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2796,12 +2796,10 @@ - - - + @@ -2828,6 +2826,9 @@ $dbName + + + @@ -2835,9 +2836,6 @@ empty($routinename) empty($routinename) - - $key - @@ -11014,18 +11012,12 @@ - $alterRealSqlQuery - $alterSqlQuery - $createUserReal $paramDbName $paramDbName $paramRoutineName $paramRoutineName $paramTableName $paramTableName - $passwordSetReal - $privilege - $realSqlQuery $row $row @@ -11042,7 +11034,6 @@ $sqlQuery $sqlQuery - $sqlQuery $user @@ -11057,10 +11048,6 @@ - - - - @@ -11100,18 +11087,9 @@ $paramDbName $paramRoutineName $paramTableName - $privilege - $queriesForDisplay[$tmpCount - 1] - $queriesForDisplay[$tmpCount - 1] - $queriesForDisplay[$tmpCount - 2] - $queriesForDisplay[$tmpCount - 2] - $queriesForDisplay[$tmpCount - 3] $queries[$tmpCount] - $queries[] - $queries[] - $queries[] $row @@ -11128,12 +11106,8 @@ string|null - $createUserShow $oneGrant $origValue - - - $sqlQuery @@ -11234,6 +11208,8 @@ $alterUserQuery $alterUserQuery $alterUserQuery + + $row1[0] @@ -15442,17 +15418,9 @@ Config::getInstance() Config::getInstance() - - $realSqlQuery - $sqlQuery - getMessage getMessage - getMessage - getMessage - getMessage - getMessage providerUnEscapeMysqlWildcards diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index b1a1c1c91d..f62a163596 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -910,7 +910,7 @@ class Privileges * @param string $hostname host name * @param string $itemType item type * - * @return mixed[] ($message, $sql_query) + * @return array{Message, string} ($message, $sql_query) */ public function getMessageAndSqlQueryForPrivilegesRevoke( string $dbname, @@ -1124,7 +1124,7 @@ class Privileges return $privilege; } - /** @return mixed[] */ + /** @return array> */ private function getGlobalAndDatabasePrivileges(DatabaseName $db): array { $listOfPrivileges = '`Select_priv`, @@ -1185,7 +1185,7 @@ class Privileges return $result->fetchAllAssoc(); } - /** @return mixed[] */ + /** @return array> */ private function getTablePrivileges(DatabaseName $db, TableName $table): array { $query = ' @@ -1207,7 +1207,7 @@ class Privileges return $result->fetchAllAssoc(); } - /** @return mixed[] */ + /** @return array> */ private function getRoutinesPrivileges(DatabaseName $db): array { $query = ' @@ -1930,7 +1930,7 @@ class Privileges /** * Update the privileges and return the success or error message * - * @return mixed[] success message or error message for update + * @return array{string, Message} success message or error message for update */ public function updatePrivileges( string $username, @@ -2309,21 +2309,19 @@ class Privileges if (empty($_POST['change_copy'])) { $error = false; - if ($createUserReal !== null) { - if (! $this->dbi->tryQuery($createUserReal)) { - $error = true; - } - - if (isset($_POST['authentication_plugin']) && ! empty($passwordSetReal)) { - $this->setProperPasswordHashing($_POST['authentication_plugin']); - if ($this->dbi->tryQuery($passwordSetReal)) { - $sqlQuery .= $passwordSetShow; - } - } - - $sqlQuery = $createUserShow . $sqlQuery; + if (! $this->dbi->tryQuery($createUserReal)) { + $error = true; } + if (isset($_POST['authentication_plugin']) && $passwordSetReal !== '') { + $this->setProperPasswordHashing($_POST['authentication_plugin']); + if ($this->dbi->tryQuery($passwordSetReal)) { + $sqlQuery .= $passwordSetShow; + } + } + + $sqlQuery = $createUserShow . $sqlQuery; + [$sqlQuery, $message] = $this->addUserAndCreateDatabase( $error, $realSqlQuery, @@ -2354,13 +2352,10 @@ class Privileges $oldUserGroup = $_POST['old_usergroup'] ?? ''; $this->setUserGroup($_POST['username'], $oldUserGroup); - if ($createUserReal !== null) { - $queries[] = $createUserReal; - } - + $queries[] = $createUserReal; $queries[] = $realSqlQuery; - if (isset($_POST['authentication_plugin']) && ! empty($passwordSetReal)) { + if (isset($_POST['authentication_plugin']) && $passwordSetReal !== '') { $this->setProperPasswordHashing($_POST['authentication_plugin']); $queries[] = $passwordSetReal; @@ -2370,11 +2365,9 @@ class Privileges // $queries_for_display, at the same position occupied // by the real query in $queries $tmpCount = count($queries); - if (isset($createUserReal)) { - $queriesForDisplay[$tmpCount - 2] = $createUserShow; - } + $queriesForDisplay[$tmpCount - 2] = $createUserShow; - if (! empty($passwordSetReal)) { + if ($passwordSetReal !== '') { $queriesForDisplay[$tmpCount - 3] = $createUserShow; $queriesForDisplay[$tmpCount - 2] = $sqlQuery; $queriesForDisplay[$tmpCount - 1] = $passwordSetShow; @@ -3017,8 +3010,7 @@ class Privileges * @param string $hostname host name * @param string $password password * - * @return mixed[] ($create_user_real, $create_user_show, $real_sql_query, $sql_query - * $password_set_real, $password_set_show, $alter_real_sql_query, $alter_sql_query) + * @return array{string, string, string, string, string, string, string, string} */ public function getSqlQueriesForDisplayAndAddUser(string $username, string $hostname, string $password): array { @@ -3079,7 +3071,7 @@ class Privileges (Compatibility::isMySqlOrPerconaDb() && $serverVersion >= 50706) || (Compatibility::isMariaDb() && $serverVersion >= 50200) ) { - $passwordSetReal = null; + $passwordSetReal = ''; // Required for binding '%' with '%s' $createUserStmt = str_replace('%', '%%', $createUserStmt); @@ -3189,10 +3181,10 @@ class Privileges || (Compatibility::isMariaDb() && $serverVersion >= 50200) ) { - $passwordSetReal = null; - $passwordSetShow = null; + $passwordSetReal = ''; + $passwordSetShow = ''; } else { - if ($passwordSetReal !== null) { + if ($passwordSetReal !== '') { $passwordSetReal .= ';'; } @@ -3239,7 +3231,7 @@ class Privileges * @param string $database Database name * @param string $routine Routine name * - * @return mixed[] + * @return array */ private function getRoutinePrivileges( string $username,