diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4c6e32e1b1..6e1ac2f400 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -312,13 +312,7 @@ parameters: - message: '#^Parameter \#1 \$row of method PhpMyAdmin\\Bookmarks\\BookmarkRepository\:\:createFromRow\(\) expects array\, array\ given\.$#' identifier: argument.type - count: 2 - path: src/Bookmarks/BookmarkRepository.php - - - - message: '#^Parameter \#1 \$row of method PhpMyAdmin\\Bookmarks\\BookmarkRepository\:\:createFromRow\(\) expects array\, mixed given\.$#' - identifier: argument.type - count: 1 + count: 3 path: src/Bookmarks/BookmarkRepository.php - @@ -3912,18 +3906,6 @@ parameters: count: 1 path: src/Controllers/Server/UserGroupsFormController.php - - - message: '#^Offset 1 might not exist on array\\|null\.$#' - identifier: offsetAccess.notFound - count: 2 - path: src/Controllers/Server/Variables/GetVariableController.php - - - - message: '#^Offset 1 might not exist on array\\|null\.$#' - identifier: offsetAccess.notFound - count: 1 - path: src/Controllers/Server/Variables/SetVariableController.php - - message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, int\|string given\.$#' identifier: argument.type @@ -4599,42 +4581,6 @@ parameters: count: 1 path: src/Controllers/Table/Maintenance/RepairController.php - - - message: '#^Parameter \#2 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:getMessage\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/Partition/AnalyzeController.php - - - - message: '#^Parameter \#2 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:getMessage\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/Partition/CheckController.php - - - - message: '#^Only booleans are allowed in an if condition, mixed given\.$#' - identifier: if.condNotBoolean - count: 1 - path: src/Controllers/Table/Partition/DropController.php - - - - message: '#^Parameter \#2 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:getMessage\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Controllers/Table/Partition/DropController.php - - - - message: '#^Parameter \#2 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:getMessage\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/Partition/OptimizeController.php - - - - message: '#^Parameter \#2 \$sqlQuery of static method PhpMyAdmin\\Html\\Generator\:\:getMessage\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Table/Partition/RepairController.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: @@ -6153,46 +6099,16 @@ parameters: count: 1 path: src/Database/CentralColumns.php - - - message: '#^Cannot access offset ''col_attribute'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 5 - path: src/Database/CentralColumns.php - - - - message: '#^Cannot access offset ''col_default'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Database/CentralColumns.php - - - - message: '#^Cannot access offset ''col_extra'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Database/CentralColumns.php - - - - message: '#^Cannot access offset ''col_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Database/CentralColumns.php - - message: '#^Cannot access offset int\<0, max\> on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 11 path: src/Database/CentralColumns.php - - - message: '#^Cannot cast mixed to int\.$#' - identifier: cast.int - count: 2 - path: src/Database/CentralColumns.php - - message: '#^Cannot cast mixed to string\.$#' identifier: cast.string - count: 2 + count: 1 path: src/Database/CentralColumns.php - @@ -6202,13 +6118,7 @@ parameters: path: src/Database/CentralColumns.php - - message: '#^Method PhpMyAdmin\\Database\\CentralColumns\:\:findExistingColNames\(\) should return array\ but returns array\\.$#' - identifier: return.type - count: 1 - path: src/Database/CentralColumns.php - - - - message: '#^Method PhpMyAdmin\\Database\\CentralColumns\:\:findExistingColumns\(\) should return array\\> but returns array\\.$#' + message: '#^Method PhpMyAdmin\\Database\\CentralColumns\:\:findExistingColNames\(\) should return array\ but returns list\\.$#' identifier: return.type count: 1 path: src/Database/CentralColumns.php @@ -6231,12 +6141,6 @@ parameters: count: 3 path: src/Database/CentralColumns.php - - - message: '#^Parameter \#1 \$bitDefaultValue of static method PhpMyAdmin\\Util\:\:convertBitDefaultValue\(\) expects string\|null, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Database/CentralColumns.php - - message: '#^Parameter \#1 \$db of method PhpMyAdmin\\Database\\CentralColumns\:\:updateOneColumn\(\) expects string, mixed given\.$#' identifier: argument.type @@ -6255,12 +6159,6 @@ parameters: count: 1 path: src/Database/CentralColumns.php - - - message: '#^Parameter \#1 \$string of function bin2hex expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Database/CentralColumns.php - - message: '#^Parameter \#1 \$string of function trim expects string, mixed given\.$#' identifier: argument.type @@ -6286,7 +6184,7 @@ parameters: path: src/Database/CentralColumns.php - - message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#' + message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#' identifier: argument.type count: 1 path: src/Database/CentralColumns.php @@ -6958,13 +6856,7 @@ parameters: path: src/DatabaseInterface.php - - message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:affectedRows\(\) should return int\|numeric\-string but returns mixed\.$#' - identifier: return.type - count: 1 - path: src/DatabaseInterface.php - - - - message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:getColumnNames\(\) should return list\ but returns array\\.$#' + message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:getColumnNames\(\) should return list\ but returns list\\.$#' identifier: return.type count: 1 path: src/DatabaseInterface.php @@ -6994,7 +6886,7 @@ parameters: path: src/DatabaseInterface.php - - message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:getTableIndexes\(\) should return array\ but returns array\\.$#' + message: '#^Method PhpMyAdmin\\DatabaseInterface\:\:getTableIndexes\(\) should return array\ but returns list\\>\.$#' identifier: return.type count: 1 path: src/DatabaseInterface.php @@ -7089,12 +6981,6 @@ parameters: count: 1 path: src/DatabaseInterface.php - - - message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#' - identifier: ternary.shortNotAllowed - count: 1 - path: src/DatabaseInterface.php - - message: '#^Variable \$roleHost on left side of \?\? always exists and is not nullable\.$#' identifier: nullCoalesce.variable @@ -10693,19 +10579,19 @@ parameters: path: src/Navigation/Nodes/NodeTable.php - - message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getEventsFromDb\(\) should return array\ but returns array\\.$#' + message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getEventsFromDb\(\) should return array\ but returns list\\.$#' identifier: return.type count: 1 path: src/Navigation/Nodes/ObjectFetcher.php - - message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getRoutines\(\) should return array\ but returns array\\.$#' + message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getRoutines\(\) should return array\ but returns list\\.$#' identifier: return.type count: 1 path: src/Navigation/Nodes/ObjectFetcher.php - - message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getTablesAndViews\(\) should return array\ but returns array\\.$#' + message: '#^Method PhpMyAdmin\\Navigation\\Nodes\\ObjectFetcher\:\:getTablesAndViews\(\) should return array\ but returns list\\>\.$#' identifier: return.type count: 1 path: src/Navigation/Nodes/ObjectFetcher.php @@ -10749,18 +10635,6 @@ parameters: count: 2 path: src/Normalization.php - - - message: '#^Cannot access offset non\-falsy\-string on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Normalization.php - - - - message: '#^Cannot cast mixed to int\.$#' - identifier: cast.int - count: 1 - path: src/Normalization.php - - message: '#^Casting to int something that''s already int\<1, max\>\.$#' identifier: cast.useless @@ -10911,12 +10785,6 @@ parameters: count: 2 path: src/Normalization.php - - - message: '#^Parameter \#6 \$totalRows of method PhpMyAdmin\\Normalization\:\:checkPartialDependency\(\) expects int, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Normalization.php - - message: '#^Variable property access on object\.$#' identifier: property.dynamicName @@ -11085,12 +10953,6 @@ parameters: count: 1 path: src/Operations.php - - - message: '#^Cannot access offset ''Table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 4 - path: src/Partitioning/Maintenance.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\DatabaseInterface\: @@ -11100,12 +10962,6 @@ parameters: count: 4 path: src/Partitioning/Partition.php - - - message: '#^Cannot access offset ''Name'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Partitioning/Partition.php - - message: '#^Cannot cast mixed to int\.$#' identifier: cast.int @@ -11118,24 +10974,12 @@ parameters: count: 2 path: src/Partitioning/Partition.php - - - message: '#^Method PhpMyAdmin\\Partitioning\\Partition\:\:getPartitionMethod\(\) should return string\|null but returns mixed\.$#' - identifier: return.type - count: 1 - path: src/Partitioning/Partition.php - - message: '#^Only booleans are allowed in an if condition, string\|false\|null given\.$#' identifier: if.condNotBoolean count: 1 path: src/Partitioning/Partition.php - - - message: '#^PHPDoc tag @var for variable \$row has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/Partitioning/Partition.php - - message: '#^PhpMyAdmin\\Partitioning\\Partition\:\:__construct\(\) does not call parent constructor from PhpMyAdmin\\Partitioning\\SubPartition\.$#' identifier: constructor.missingParentCall @@ -12618,7 +12462,7 @@ parameters: - message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#' identifier: argument.type - count: 3 + count: 2 path: src/Plugins/Export/ExportSql.php - @@ -12646,7 +12490,7 @@ parameters: path: src/Plugins/Export/ExportSql.php - - message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Events\:\:getDefinition\(\) expects string, mixed given\.$#' + message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Events\:\:getDefinition\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: src/Plugins/Export/ExportSql.php @@ -12762,18 +12606,6 @@ parameters: count: 3 path: src/Plugins/Export/ExportXml.php - - - message: '#^Cannot access offset ''DEFAULT_CHARACTER_SET_NAME'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportXml.php - - - - message: '#^Cannot access offset ''DEFAULT_COLLATION_NAME'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportXml.php - - message: '#^Cannot access offset ''columns'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12825,17 +12657,17 @@ parameters: - message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#' identifier: argument.type - count: 3 + count: 1 path: src/Plugins/Export/ExportXml.php - message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, string\|null given\.$#' identifier: argument.type - count: 2 + count: 4 path: src/Plugins/Export/ExportXml.php - - message: '#^Parameter \#3 \$names of method PhpMyAdmin\\Plugins\\Export\\ExportXml\:\:exportDefinitions\(\) expects array\, array\ given\.$#' + message: '#^Parameter \#3 \$names of method PhpMyAdmin\\Plugins\\Export\\ExportXml\:\:exportDefinitions\(\) expects array\, list\ given\.$#' identifier: argument.type count: 1 path: src/Plugins/Export/ExportXml.php @@ -15147,18 +14979,6 @@ parameters: count: 2 path: src/Replication/Replication.php - - - message: '#^Cannot access offset ''File'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Replication/Replication.php - - - - message: '#^Cannot access offset ''Position'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Replication/Replication.php - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed @@ -15166,7 +14986,7 @@ parameters: path: src/Replication/Replication.php - - message: '#^Method PhpMyAdmin\\Replication\\Replication\:\:replicaBinLogPrimary\(\) should return array\{File\?\: string, Position\?\: string\} but returns array\{\}\|array\{File\: mixed, Position\: mixed\}\.$#' + message: '#^Method PhpMyAdmin\\Replication\\Replication\:\:replicaBinLogPrimary\(\) should return array\{File\?\: string, Position\?\: string\} but returns array\{\}\|array\{File\: string\|null, Position\: string\|null\}\.$#' identifier: return.type count: 1 path: src/Replication/Replication.php @@ -15546,12 +15366,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: '#^Binary operation "\." between mixed and ";\\n\\n" results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/Server/Privileges.php - - message: '#^Binary operation "\." between mixed and ''&\#27;'' results in an error\.$#' identifier: binaryOp.invalid @@ -15579,18 +15393,6 @@ parameters: count: 2 path: src/Server/Privileges.php - - - message: '#^Cannot access offset ''CHARACTER_MAXIMUM_LENGTH'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Server/Privileges.php - - - - message: '#^Cannot access offset ''COLUMN_NAME'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Server/Privileges.php - - message: '#^Cannot access offset ''Column_priv'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -15717,18 +15519,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: '#^Offset ''@@old_passwords'' might not exist on array\\|null\.$#' - identifier: offsetAccess.notFound - count: 1 - path: src/Server/Privileges.php - - - - message: '#^Offset ''Type'' might not exist on array\\|null\.$#' - identifier: offsetAccess.notFound - count: 4 - path: src/Server/Privileges.php - - message: '#^Only booleans are allowed in &&, mixed given on the right side\.$#' identifier: booleanAnd.rightNotBoolean @@ -17109,16 +16899,10 @@ parameters: count: 2 path: src/Table/Table.php - - - message: '#^Cannot access offset ''Extra'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: src/Table/Table.php - - message: '#^Cannot access offset ''Field'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 3 + count: 2 path: src/Table/Table.php - @@ -17217,12 +17001,6 @@ parameters: count: 1 path: src/Table/Table.php - - - message: '#^Method PhpMyAdmin\\Table\\Table\:\:getNonGeneratedColumns\(\) should return array\ but returns list\\.$#' - identifier: return.type - count: 1 - path: src/Table/Table.php - - message: '#^Method PhpMyAdmin\\Table\\Table\:\:getUiPrefsFromDb\(\) should return array\ but returns mixed\.$#' identifier: return.type @@ -17254,7 +17032,7 @@ parameters: path: src/Table/Table.php - - message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#' + message: '#^Parameter \#1 \$haystack of function str_contains expects string, string\|null given\.$#' identifier: argument.type count: 3 path: src/Table/Table.php @@ -17262,7 +17040,7 @@ parameters: - message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#' identifier: argument.type - count: 2 + count: 1 path: src/Table/Table.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 9fe8f3e0f4..4d8f427cc9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -64,13 +64,8 @@ + - - - - - - bookmarkFeature]]> @@ -2314,9 +2309,6 @@ - - - @@ -2328,9 +2320,6 @@ - - - @@ -2878,34 +2867,21 @@ - - - - - - - - - - - - - @@ -2916,9 +2892,6 @@ - - - @@ -3771,6 +3744,12 @@ + + dbi->fetchSingleColumn($query, ConnectionType::ControlUser)]]> + + + + @@ -3783,9 +3762,6 @@ - - - @@ -3799,42 +3775,25 @@ - - - - - - - - - - - - - - - dbi->fetchResult($query, null, null, ConnectionType::ControlUser)]]> - - - + @@ -4229,9 +4188,6 @@ - - fetchResult($sql, null, 'Field', $connectionType)]]> - @@ -4281,7 +4237,7 @@ - fetchResult($sql, null, null, $connectionType)]]> + fetchResultSimple($sql, $connectionType)]]> ]]> - - + fetchAllAssoc(), 'Field')]]> ]]> - + @@ -6188,14 +6143,16 @@ - - dbi->fetchResult($query)]]> - dbi->fetchResult($query)]]> - dbi->fetchResult($query)]]> + + dbi->fetchResultSimple($query)]]> + dbi->fetchSingleColumn($query)]]> + dbi->fetchSingleColumn($query)]]> + + - + @@ -6243,7 +6200,6 @@ $key]]> $key]]> - @@ -6264,7 +6220,6 @@ - @@ -6277,11 +6232,9 @@ - - @@ -6443,28 +6396,12 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -6473,27 +6410,16 @@ - - - - - - - - description]]> expression]]> method]]> name]]> - - - - - - - + + + + @@ -6501,6 +6427,7 @@ fetchValue('SELECT @@have_partitioning;')]]> + @@ -7177,8 +7104,6 @@ - - @@ -7200,7 +7125,6 @@ - name]]> references->table->table]]> @@ -7224,6 +7148,7 @@ + @@ -7325,25 +7250,21 @@ + + + - - - - - - - - - + + @@ -8842,26 +8763,20 @@ + + + - - - - - - - - - - + - + @@ -9054,10 +8969,6 @@ - - - - @@ -9073,11 +8984,9 @@ - - @@ -9089,11 +8998,8 @@ - - - @@ -9172,10 +9078,6 @@ - - - - @@ -9193,6 +9095,7 @@ + @@ -9844,8 +9747,6 @@ - - @@ -9853,7 +9754,6 @@ uiprefs[$property->value]]]> uiprefs[$property->value]]]> - @@ -9861,9 +9761,6 @@ dbName][$this->name]]]> - - - @@ -9887,12 +9784,9 @@ - - - @@ -9905,9 +9799,7 @@ - ]]> - @@ -9921,6 +9813,8 @@ + + refDbName]]> refTableName]]> diff --git a/src/Bookmarks/BookmarkRepository.php b/src/Bookmarks/BookmarkRepository.php index f4f5c40151..9d68f99221 100644 --- a/src/Bookmarks/BookmarkRepository.php +++ b/src/Bookmarks/BookmarkRepository.php @@ -95,7 +95,7 @@ final class BookmarkRepository $query .= ' ORDER BY label ASC'; - $result = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); + $result = $this->dbi->fetchResultSimple($query, ConnectionType::ControlUser); $bookmarks = []; foreach ($result as $row) { @@ -134,7 +134,7 @@ final class BookmarkRepository $query .= ' LIMIT 1'; $result = $this->dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser); - if ($result !== null) { + if ($result !== []) { return $this->createFromRow($result); } @@ -162,7 +162,7 @@ final class BookmarkRepository . ' LIMIT 1'; $result = $this->dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser); - if ($result !== null) { + if ($result !== []) { return $this->createFromRow($result); } diff --git a/src/ConfigStorage/Relation.php b/src/ConfigStorage/Relation.php index f0570b84bb..ec98f98a81 100644 --- a/src/ConfigStorage/Relation.php +++ b/src/ConfigStorage/Relation.php @@ -478,7 +478,7 @@ class Relation . ' AND `table_name` = ' . $this->dbi->quoteString($table); $row = $this->dbi->fetchSingleRow($dispQuery, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser); - if (isset($row['display_field'])) { + if ($row['display_field'] !== null) { return $row['display_field']; } } @@ -662,9 +662,9 @@ class Relation * * @param string $username the username * - * @return mixed[]|bool list of history items + * @return mixed[]|false list of history items */ - public function getHistory(string $username): array|bool + public function getHistory(string $username): array|false { $sqlHistoryFeature = $this->getRelationParameters()->sqlHistoryFeature; if ($sqlHistoryFeature === null) { @@ -693,7 +693,7 @@ class Relation WHERE `username` = ' . $this->dbi->quoteString($username) . ' ORDER BY `id` DESC'; - return $this->dbi->fetchResult($histQuery, null, null, ConnectionType::ControlUser); + return $this->dbi->fetchResultSimple($histQuery, ConnectionType::ControlUser); } /** diff --git a/src/Controllers/Database/MultiTableQuery/TablesController.php b/src/Controllers/Database/MultiTableQuery/TablesController.php index 09dd98196e..6da9db31d4 100644 --- a/src/Controllers/Database/MultiTableQuery/TablesController.php +++ b/src/Controllers/Database/MultiTableQuery/TablesController.php @@ -29,7 +29,7 @@ final class TablesController implements InvocableController $tablesListForQuery = array_map($this->dbi->quoteString(...), $tables); - $constrains = $this->dbi->fetchResult( + $constrains = $this->dbi->fetchResultSimple( QueryGenerator::getInformationSchemaForeignKeyConstraintsRequest( $this->dbi->quoteString($db), implode(',', $tablesListForQuery), diff --git a/src/Controllers/Table/SearchController.php b/src/Controllers/Table/SearchController.php index 96dcdefa44..2dcbc82505 100644 --- a/src/Controllers/Table/SearchController.php +++ b/src/Controllers/Table/SearchController.php @@ -304,9 +304,9 @@ final class SearchController implements InvocableController * * @param string $column Column name * - * @return mixed[]|null + * @return array */ - private function getColumnMinMax(string $column): array|null + private function getColumnMinMax(string $column): array { $sqlQuery = 'SELECT MIN(' . Util::backquote($column) . ') AS `min`, ' . 'MAX(' . Util::backquote($column) . ') AS `max` ' diff --git a/src/Database/CentralColumns.php b/src/Database/CentralColumns.php index c5139452f7..9fcd94e2d6 100644 --- a/src/Database/CentralColumns.php +++ b/src/Database/CentralColumns.php @@ -31,6 +31,7 @@ use function implode; use function in_array; use function is_array; use function is_bool; +use function is_string; use function mb_strtoupper; use function sprintf; use function trim; @@ -100,7 +101,7 @@ class CentralColumns * @param int $from starting offset of first result * @param int $num maximum number of results to return * - * @return mixed[] list of $num columns present in central columns list + * @return list> list of $num columns present in central columns list * starting at offset $from for the given database */ public function getColumnsList(string $db, int $from = 0, int $num = 25): array @@ -122,10 +123,9 @@ class CentralColumns . 'LIMIT ' . $from . ', ' . $num . ';'; } - $hasList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); - $this->handleColumnExtra($hasList); + $hasList = $this->dbi->fetchResultSimple($query, ConnectionType::ControlUser); - return $hasList; + return $this->handleColumnExtra($hasList); } /** @@ -147,12 +147,8 @@ class CentralColumns $query = 'SELECT count(db_name) FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' ' . 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ';'; - $res = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); - if (isset($res[0])) { - return (int) $res[0]; - } - return 0; + return (int) $this->dbi->fetchValue($query, 0, ConnectionType::ControlUser); } /** @@ -180,7 +176,7 @@ class CentralColumns . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');'; - return $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); + return $this->dbi->fetchSingleColumn($query, ConnectionType::ControlUser); } /** @@ -207,10 +203,9 @@ class CentralColumns $query = 'SELECT * FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');'; - $hasList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); - $this->handleColumnExtra($hasList); + $hasList = $this->dbi->fetchResultSimple($query, ConnectionType::ControlUser); - return $hasList; + return $this->handleColumnExtra($hasList); } /** @@ -667,7 +662,7 @@ class CentralColumns * @param string $db selected database * @param string $table current table name * - * @return mixed[] encoded list of columns present in central list for the given database + * @return list> encoded list of columns present in central list for the given database */ public function getListRaw(string $db, string $table): array { @@ -692,19 +687,20 @@ class CentralColumns $query .= ';'; } - $columnsList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); - $this->handleColumnExtra($columnsList); + $columnsList = $this->dbi->fetchResultSimple($query, ConnectionType::ControlUser); - return $columnsList; + return $this->handleColumnExtra($columnsList); } /** * Column `col_extra` is used to store both extra and attributes for a column. * This method separates them. * - * @param mixed[] $columnsList columns list + * @param list> $columnsList columns list + * + * @return list> */ - private function handleColumnExtra(array &$columnsList): void + private function handleColumnExtra(array $columnsList): array { foreach ($columnsList as &$row) { $vals = explode(',', $row['col_extra']); @@ -723,6 +719,8 @@ class CentralColumns $row['col_extra'] = in_array('auto_increment', $vals, true) ? 'auto_increment' : ''; } + + return $columnsList; } /** @@ -771,10 +769,10 @@ class CentralColumns $query = 'SELECT COUNT(db_name) FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ($num === 0 ? '' : 'LIMIT ' . $from . ', ' . $num) . ';'; - $result = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); + $result = $this->dbi->fetchValue($query, 0, ConnectionType::ControlUser); - if (isset($result[0])) { - return (int) $result[0]; + if (is_string($result)) { + return (int) $result; } return -1; diff --git a/src/Database/Designer.php b/src/Database/Designer.php index 3e0d261c72..54462d8964 100644 --- a/src/Database/Designer.php +++ b/src/Database/Designer.php @@ -17,7 +17,6 @@ use PhpMyAdmin\Util; use stdClass; use function __; -use function is_array; use function json_decode; use function str_contains; @@ -146,7 +145,7 @@ class Designer . ';'; $result = $this->dbi->fetchSingleRow($query); - if (is_array($result)) { + if ($result !== []) { $params = json_decode((string) $result['settings_data'], true); } } diff --git a/src/Database/Designer/Common.php b/src/Database/Designer/Common.php index 8e05a8dd93..b56ccdb77e 100644 --- a/src/Database/Designer/Common.php +++ b/src/Database/Designer/Common.php @@ -330,7 +330,7 @@ class Common . ' FROM ' . Util::backquote($pdfFeature->database) . '.' . Util::backquote($pdfFeature->pdfPages) . ' WHERE `page_descr` = ' . $this->dbi->quoteString($pg, ConnectionType::ControlUser); - $pageNos = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser); + $pageNos = $this->dbi->fetchResultSimple($query, ConnectionType::ControlUser); return $pageNos !== []; } @@ -669,7 +669,7 @@ class Common ConnectionType::ControlUser, ); - if ($origData !== null && $origData !== []) { + if ($origData !== []) { $origData = json_decode($origData['settings_data'], true); $origData[$index] = $value; $origData = json_encode($origData); diff --git a/src/Database/Events.php b/src/Database/Events.php index ca7f732c44..bfacccc5a9 100644 --- a/src/Database/Events.php +++ b/src/Database/Events.php @@ -223,7 +223,7 @@ class Events . ' AND EVENT_NAME=' . $this->dbi->quoteString($name); $query = 'SELECT ' . $columns . ' FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE ' . $where . ';'; $item = $this->dbi->fetchSingleRow($query); - if ($item === null || $item === []) { + if ($item === []) { return null; } @@ -367,7 +367,7 @@ class Events } $result = []; - $events = $this->dbi->fetchResult($query); + $events = $this->dbi->fetchResultSimple($query); /** @var string[] $event */ foreach ($events as $event) { diff --git a/src/Database/Routines.php b/src/Database/Routines.php index 655ec85884..348b4f91ef 100644 --- a/src/Database/Routines.php +++ b/src/Database/Routines.php @@ -432,7 +432,7 @@ class Routines $routine = $this->dbi->fetchSingleRow($query); - if ($routine === null || $routine === []) { + if ($routine === []) { return null; } @@ -1256,7 +1256,7 @@ class Routines in_array($which, ['FUNCTION', 'PROCEDURE'], true) ? $which : null, $name === '' ? null : $dbi->quoteString($name), ); - $routines = $dbi->fetchResult($query); + $routines = $dbi->fetchResultSimple($query); } else { $routines = []; @@ -1266,7 +1266,7 @@ class Routines $query .= ' AND `Name` = ' . $dbi->quoteString($name); } - $routines = $dbi->fetchResult($query); + $routines = $dbi->fetchResultSimple($query); } if ($which === 'PROCEDURE' || $which == null) { @@ -1275,7 +1275,7 @@ class Routines $query .= ' AND `Name` = ' . $dbi->quoteString($name); } - $routines = array_merge($routines, $dbi->fetchResult($query)); + $routines = array_merge($routines, $dbi->fetchResultSimple($query)); } } @@ -1319,7 +1319,7 @@ class Routines public static function getFunctionNames(DatabaseInterface $dbi, string $db): array { /** @psalm-var list $functions */ - $functions = $dbi->fetchResult('SHOW FUNCTION STATUS;'); + $functions = $dbi->fetchResultSimple('SHOW FUNCTION STATUS;'); $names = []; foreach ($functions as $function) { if ($function['Db'] !== $db || $function['Type'] !== 'FUNCTION' || $function['Name'] === '') { @@ -1339,7 +1339,7 @@ class Routines public static function getProcedureNames(DatabaseInterface $dbi, string $db): array { /** @psalm-var list $procedures */ - $procedures = $dbi->fetchResult('SHOW PROCEDURE STATUS;'); + $procedures = $dbi->fetchResultSimple('SHOW PROCEDURE STATUS;'); $names = []; foreach ($procedures as $procedure) { if ($procedure['Db'] !== $db || $procedure['Type'] !== 'PROCEDURE' || $procedure['Name'] === '') { diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index e018c8f74b..75795d855a 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -137,6 +137,9 @@ class DatabaseInterface implements DbalInterface private ListDatabase|null $databaseList = null; private readonly Config $config; + /** @var int|numeric-string */ + private static int|string $cachedAffectedRows = -1; + /** @param DbiExtension $extension Object to be used for database queries */ public function __construct(private DbiExtension $extension) { @@ -199,7 +202,7 @@ class DatabaseInterface implements DbalInterface } if ($cacheAffectedRows) { - $GLOBALS['cached_affected_rows'] = $this->affectedRows($connectionType, false); + self::$cachedAffectedRows = $this->affectedRows($connectionType, false); } if ($this->config->config->debug->sql) { @@ -300,13 +303,19 @@ class DatabaseInterface implements DbalInterface return []; } - /** @var array $tables */ - $tables = $this->fetchResult( + $result = $this->tryQuery( 'SHOW TABLES FROM ' . Util::backquote($database) . ';', - null, - 0, $connectionType, + cacheAffectedRows: false, ); + + if ($result === false) { + return []; + } + + /** @var list $tables */ + $tables = $result->fetchAllColumn(); + if ($this->config->settings['NaturalOrder']) { usort($tables, strnatcasecmp(...)); } @@ -980,8 +989,14 @@ class DatabaseInterface implements DbalInterface ): array { $sql = QueryGenerator::getColumnsSql($database, $table); + $result = $this->tryQuery($sql, $connectionType, cacheAffectedRows: false); + + if ($result === false) { + return []; + } + // We only need the 'Field' column which contains the table's column names - return $this->fetchResult($sql, null, 'Field', $connectionType); + return array_column($result->fetchAllAssoc(), 'Field'); } /** @@ -1017,7 +1032,7 @@ class DatabaseInterface implements DbalInterface ): array { $sql = QueryGenerator::getTableIndexesSql($database, $table); - return $this->fetchResult($sql, null, null, $connectionType); + return $this->fetchResultSimple($sql, $connectionType); } /** @@ -1080,7 +1095,7 @@ class DatabaseInterface implements DbalInterface { $version = $this->fetchSingleRow('SELECT @@version, @@version_comment'); - if (is_array($version)) { + if ($version !== []) { $this->setVersion($version); } @@ -1196,19 +1211,19 @@ class DatabaseInterface implements DbalInterface * @param string $type NUM|ASSOC|BOTH returned array should either numeric associative or both * @psalm-param DatabaseInterface::FETCH_NUM|DatabaseInterface::FETCH_ASSOC $type * - * @return array|null + * @return array */ public function fetchSingleRow( string $query, string $type = DbalInterface::FETCH_ASSOC, ConnectionType $connectionType = ConnectionType::User, - ): array|null { + ): array { $result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false); if ($result === false) { - return null; + return []; } - return $this->fetchByMode($result, $type) ?: null; + return $this->fetchByMode($result, $type); } /** @@ -1278,17 +1293,17 @@ class DatabaseInterface implements DbalInterface * // $users['admin']['John Doe'] = '123' * * - * @param string $query query to execute - * @param string|int|mixed[]|null $key field-name or offset + * @param string $query query to execute + * @param string|int|mixed[] $key field-name or offset * used as key for array * or array of those - * @param string|int|null $value value-name or offset used as value for array + * @param string|int|null $value value-name or offset used as value for array * * @return mixed[] resultrows or values indexed by $key */ public function fetchResult( string $query, - string|int|array|null $key = null, + string|int|array $key, string|int|null $value = null, ConnectionType $connectionType = ConnectionType::User, ): array { @@ -1301,15 +1316,6 @@ class DatabaseInterface implements DbalInterface return []; } - if ($key === null) { - // no nested array if only one field is in result - if ($value === 0 || $result->numFields() === 1) { - return $result->fetchAllColumn(); - } - - return $value === null ? $result->fetchAllAssoc() : array_column($result->fetchAllAssoc(), $value); - } - if (is_array($key)) { while ($row = $result->fetchAssoc()) { $resultTarget =& $resultRows; @@ -1346,6 +1352,34 @@ class DatabaseInterface implements DbalInterface return $resultRows; } + /** @return list> */ + public function fetchResultSimple( + string $query, + ConnectionType $connectionType = ConnectionType::User, + ): array { + $result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false); + + if ($result === false) { + return []; + } + + return $result->fetchAllAssoc(); + } + + /** @return list */ + public function fetchSingleColumn( + string $query, + ConnectionType $connectionType = ConnectionType::User, + ): array { + $result = $this->tryQuery($query, $connectionType, cacheAffectedRows: false); + + if ($result === false) { + return []; + } + + return $result->fetchAllColumn(); + } + /** * Get supported SQL compatibility modes * @@ -1562,7 +1596,7 @@ class DatabaseInterface implements DbalInterface private function getCurrentUserGrants(): array { /** @var string[] $grants */ - $grants = $this->fetchResult('SHOW GRANTS FOR CURRENT_USER();'); + $grants = $this->fetchSingleColumn('SHOW GRANTS FOR CURRENT_USER();'); return $grants; } @@ -1785,7 +1819,7 @@ class DatabaseInterface implements DbalInterface } if ($getFromCache) { - return $GLOBALS['cached_affected_rows']; + return self::$cachedAffectedRows; } return $this->extension->affectedRows($this->connections[$connectionType->value]); diff --git a/src/Dbal/DbalInterface.php b/src/Dbal/DbalInterface.php index 4e6776a204..dd818ec85d 100644 --- a/src/Dbal/DbalInterface.php +++ b/src/Dbal/DbalInterface.php @@ -302,13 +302,13 @@ interface DbalInterface * @param string $type NUM|ASSOC returned array should either numeric associative or both * @psalm-param self::FETCH_NUM|self::FETCH_ASSOC $type * - * @return array|null + * @return array */ public function fetchSingleRow( string $query, string $type = DbalInterface::FETCH_ASSOC, ConnectionType $connectionType = ConnectionType::User, - ): array|null; + ): array; /** * returns all rows in the resultset in one array @@ -352,15 +352,15 @@ interface DbalInterface * // $users['admin']['John Doe'] = '123' * * - * @param string $query query to execute - * @param string|int|mixed[]|null $key field-name or offset used as key for array or array of those - * @param string|int|null $value value-name or offset used as value for array + * @param string $query query to execute + * @param string|int|mixed[] $key field-name or offset used as key for array or array of those + * @param string|int|null $value value-name or offset used as value for array * * @return mixed[] resultrows or values indexed by $key */ public function fetchResult( string $query, - string|int|array|null $key = null, + string|int|array $key, string|int|null $value = null, ConnectionType $connectionType = ConnectionType::User, ): array; diff --git a/src/ListDatabase.php b/src/ListDatabase.php index 6c43d72ef7..4ace28377e 100644 --- a/src/ListDatabase.php +++ b/src/ListDatabase.php @@ -100,7 +100,8 @@ class ListDatabase extends ArrayObject } if ($command !== '') { - $databaseList = $this->dbi->fetchResult($command); + /** @var string[] $databaseList */ + $databaseList = $this->dbi->fetchSingleColumn($command); } if ($this->config->settings['NaturalOrder']) { diff --git a/src/Navigation/Nodes/Node.php b/src/Navigation/Nodes/Node.php index 746a266a8e..2170141069 100644 --- a/src/Navigation/Nodes/Node.php +++ b/src/Navigation/Nodes/Node.php @@ -609,7 +609,7 @@ class Node * @param int $pos The offset of the list within the results. * @param string $searchClause A string used to filter the results of the query. * - * @return mixed[] + * @return list */ private function getDataFromInfoSchema(int $pos, string $searchClause): array { @@ -626,7 +626,7 @@ class Node $maxItems, ); - return $dbi->fetchResult($query); + return $dbi->fetchSingleColumn($query); } $dbSeparator = $this->config->settings['NavigationTreeDbSeparator']; @@ -643,14 +643,14 @@ class Node $maxItems, ); - return $dbi->fetchResult($query); + return $dbi->fetchSingleColumn($query); } /** * @param int $pos The offset of the list within the results. * @param string $searchClause A string used to filter the results of the query. * - * @return mixed[] + * @return list */ private function getDataFromShowDatabases(int $pos, string $searchClause): array { @@ -725,14 +725,14 @@ class Node implode('OR', $subClauses), ); - return $dbi->fetchResult($query); + return $dbi->fetchSingleColumn($query); } /** * @param int $pos The offset of the list within the results. * @param string $searchClause A string used to filter the results of the query. * - * @return mixed[] + * @return list */ private function getDataFromShowDatabasesLike(UserPrivileges $userPrivileges, int $pos, string $searchClause): array { diff --git a/src/Navigation/Nodes/NodeTable.php b/src/Navigation/Nodes/NodeTable.php index 43fc7009c6..6e92dd1e2f 100644 --- a/src/Navigation/Nodes/NodeTable.php +++ b/src/Navigation/Nodes/NodeTable.php @@ -164,7 +164,7 @@ class NodeTable extends NodeDatabaseChild $query .= 'AND `TABLE_SCHEMA`=' . $dbi->quoteString($db) . ' '; $query .= 'ORDER BY `COLUMN_NAME` ASC '; $query .= 'LIMIT ' . $pos . ', ' . $maxItems; - $retval = $dbi->fetchResult($query); + $retval = $dbi->fetchResultSimple($query); break; } @@ -229,7 +229,7 @@ class NodeTable extends NodeDatabaseChild . Util::getCollateForIS() . '=' . $dbi->quoteString($table) . ' '; $query .= 'ORDER BY `TRIGGER_NAME` ASC '; $query .= 'LIMIT ' . $pos . ', ' . $maxItems; - $retval = $dbi->fetchResult($query); + $retval = $dbi->fetchSingleColumn($query); break; } diff --git a/src/Navigation/Nodes/ObjectFetcher.php b/src/Navigation/Nodes/ObjectFetcher.php index c2d8f0789b..84f2c21a4d 100644 --- a/src/Navigation/Nodes/ObjectFetcher.php +++ b/src/Navigation/Nodes/ObjectFetcher.php @@ -121,7 +121,7 @@ class ObjectFetcher $query .= ' ORDER BY `EVENT_NAME` ASC'; - return $this->dbi->fetchResult($query); + return $this->dbi->fetchSingleColumn($query); } $query = 'SHOW EVENTS FROM ' . Util::backquote($realName); @@ -181,7 +181,7 @@ class ObjectFetcher $query .= ' ORDER BY `TABLE_NAME` ASC'; - return $this->dbi->fetchResult($query); + return $this->dbi->fetchResultSimple($query); } $query = 'SHOW FULL TABLES FROM '; @@ -225,7 +225,7 @@ class ObjectFetcher $query .= ' ORDER BY `ROUTINE_NAME` ASC'; - return $this->dbi->fetchResult($query); + return $this->dbi->fetchSingleColumn($query); } $query = 'SHOW ' . $routineType . ' STATUS WHERE `Db`=' . $this->dbi->quoteString($realName); diff --git a/src/Normalization.php b/src/Normalization.php index 3258195045..7b578eae22 100644 --- a/src/Normalization.php +++ b/src/Normalization.php @@ -899,11 +899,10 @@ class Normalization $columns[] = Util::backquote($column); } - $totalRowsRes = $this->dbi->fetchResult( + $totalRows = (int) $this->dbi->fetchValue( 'SELECT COUNT(*) FROM (SELECT * FROM ' . Util::backquote($table) . ' LIMIT 500) as dt;', ); - $totalRows = $totalRowsRes[0]; $primary = Index::getPrimary($this->dbi, $table, $db); $primarycols = $primary === null ? [] : $primary->getColumns(); $pk = []; @@ -988,8 +987,7 @@ class Normalization . 'COUNT(DISTINCT ' . $partialKey . ',' . $column . ') as pkColCnt ' . 'FROM (SELECT * FROM ' . Util::backquote($table) . ' LIMIT 500) as dt;'; - $res = $this->dbi->fetchResult($query); - $pkColCnt = $res[0]; + $pkColCnt = $this->dbi->fetchValue($query); if ($pkCnt !== 0 && $pkCnt === $colCnt && $colCnt == $pkColCnt) { return true; } @@ -1008,7 +1006,6 @@ class Normalization */ private function findDistinctValuesCount(array $columns, string $table): array { - $result = []; $query = 'SELECT '; foreach ($columns as $column) { if ($column === '') { @@ -1016,20 +1013,24 @@ class Normalization } //each column is already backquoted - $query .= 'COUNT(DISTINCT ' . $column . ') as \'' - . $column . '_cnt\', '; + $query .= 'COUNT(DISTINCT ' . $column . ') as \'' . $column . '_cnt\', '; } $query = trim($query, ', '); $query .= ' FROM (SELECT * FROM ' . Util::backquote($table) . ' LIMIT 500) as dt;'; - $res = $this->dbi->fetchResult($query); + $res = $this->dbi->fetchSingleRow($query); + if ($res === []) { + return []; + } + + $result = []; foreach ($columns as $column) { if ($column === '') { continue; } - $result[$column] = (int) ($res[0][$column . '_cnt'] ?? null); + $result[$column] = (int) $res[$column . '_cnt']; } return $result; diff --git a/src/Operations.php b/src/Operations.php index 249a6fea93..abcc6dcad7 100644 --- a/src/Operations.php +++ b/src/Operations.php @@ -247,7 +247,7 @@ class Operations public function runEventDefinitionsForDb(string $db, DatabaseName $newDatabaseName): void { /** @var string[] $eventNames */ - $eventNames = $this->dbi->fetchResult( + $eventNames = $this->dbi->fetchSingleColumn( 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= ' . $this->dbi->quoteString($db) . ';', ); diff --git a/src/Partitioning/Maintenance.php b/src/Partitioning/Maintenance.php index 9ebb2a7b4f..f83a8b58ac 100644 --- a/src/Partitioning/Maintenance.php +++ b/src/Partitioning/Maintenance.php @@ -19,7 +19,7 @@ final class Maintenance { } - /** @return mixed[] */ + /** @return array{array>>, string} */ public function analyze(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -29,7 +29,7 @@ final class Maintenance ); $this->dbi->selectDb($db); - $result = $this->dbi->fetchResult($query); + $result = $this->dbi->fetchResultSimple($query); $rows = []; foreach ($result as $row) { @@ -39,7 +39,7 @@ final class Maintenance return [$rows, $query]; } - /** @return mixed[] */ + /** @return array{array>>, string} */ public function check(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -49,7 +49,7 @@ final class Maintenance ); $this->dbi->selectDb($db); - $result = $this->dbi->fetchResult($query); + $result = $this->dbi->fetchResultSimple($query); $rows = []; foreach ($result as $row) { @@ -59,7 +59,7 @@ final class Maintenance return [$rows, $query]; } - /** @return mixed[] */ + /** @return array{bool, string} */ public function drop(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -74,7 +74,7 @@ final class Maintenance return [(bool) $result, $query]; } - /** @return mixed[] */ + /** @return array{array>>, string} */ public function optimize(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -84,7 +84,7 @@ final class Maintenance ); $this->dbi->selectDb($db); - $result = $this->dbi->fetchResult($query); + $result = $this->dbi->fetchResultSimple($query); $rows = []; foreach ($result as $row) { @@ -94,10 +94,7 @@ final class Maintenance return [$rows, $query]; } - /** - * @return array - * @psalm-return array{bool, string} - */ + /** @return array{bool, string} */ public function rebuild(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -112,7 +109,7 @@ final class Maintenance return [(bool) $result, $query]; } - /** @return mixed[] */ + /** @return array{array>>, string} */ public function repair(DatabaseName $db, TableName $table, string $partition): array { $query = sprintf( @@ -122,7 +119,7 @@ final class Maintenance ); $this->dbi->selectDb($db); - $result = $this->dbi->fetchResult($query); + $result = $this->dbi->fetchResultSimple($query); $rows = []; foreach ($result as $row) { @@ -132,10 +129,7 @@ final class Maintenance return [$rows, $query]; } - /** - * @return array - * @psalm-return array{bool, string} - */ + /** @return array{bool, string} */ public function truncate(DatabaseName $db, TableName $table, string $partition): array { if (Table::get($table->getName(), $db->getName(), $this->dbi)->isView()) { diff --git a/src/Partitioning/Partition.php b/src/Partitioning/Partition.php index edf0f181c3..1440b83073 100644 --- a/src/Partitioning/Partition.php +++ b/src/Partitioning/Partition.php @@ -143,14 +143,13 @@ class Partition extends SubPartition { if (self::havePartitioning()) { $dbi = DatabaseInterface::getInstance(); - $result = $dbi->fetchResult( + $result = $dbi->fetchResultSimple( 'SELECT * FROM `information_schema`.`PARTITIONS`' . ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db) . ' AND `TABLE_NAME` = ' . $dbi->quoteString($table), ); if ($result !== []) { $partitionMap = []; - /** @var array $row */ foreach ($result as $row) { if (isset($partitionMap[$row['PARTITION_NAME']])) { $partition = $partitionMap[$row['PARTITION_NAME']]; @@ -179,14 +178,14 @@ class Partition extends SubPartition * @param string $db database name * @param string $table table name * - * @return mixed[] of partition names + * @return list of partition names */ public static function getPartitionNames(string $db, string $table): array { if (self::havePartitioning()) { $dbi = DatabaseInterface::getInstance(); - return $dbi->fetchResult( + return $dbi->fetchSingleColumn( 'SELECT DISTINCT `PARTITION_NAME` FROM `information_schema`.`PARTITIONS`' . ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db) . ' AND `TABLE_NAME` = ' . $dbi->quoteString($table), @@ -208,14 +207,14 @@ class Partition extends SubPartition { if (self::havePartitioning()) { $dbi = DatabaseInterface::getInstance(); - $partitionMethod = $dbi->fetchResult( + $partitionMethod = $dbi->fetchValue( 'SELECT `PARTITION_METHOD` FROM `information_schema`.`PARTITIONS`' . ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db) . ' AND `TABLE_NAME` = ' . $dbi->quoteString($table) . ' LIMIT 1', ); - if ($partitionMethod !== []) { - return $partitionMethod[0]; + if ($partitionMethod !== false) { + return $partitionMethod; } } @@ -237,7 +236,7 @@ class Partition extends SubPartition self::$havePartitioning = true; } else { // see https://dev.mysql.com/doc/refman/5.6/en/partitioning.html - $plugins = $dbi->fetchResult('SHOW PLUGINS'); + $plugins = $dbi->fetchResultSimple('SHOW PLUGINS'); foreach ($plugins as $value) { if ($value['Name'] === 'partition') { self::$havePartitioning = true; diff --git a/src/Plugins/Export/ExportSql.php b/src/Plugins/Export/ExportSql.php index 034d55ad82..1e6e5f6dd0 100644 --- a/src/Plugins/Export/ExportSql.php +++ b/src/Plugins/Export/ExportSql.php @@ -980,7 +980,7 @@ class ExportSql extends ExportPlugin $delimiter = '$$'; $dbi = DatabaseInterface::getInstance(); - $eventNames = $dbi->fetchResult( + $eventNames = $dbi->fetchSingleColumn( 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE' . ' EVENT_SCHEMA= ' . $dbi->quoteString($db), ); diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php index 3b1c92c485..b401613eb8 100644 --- a/src/Plugins/Export/ExportXml.php +++ b/src/Plugins/Export/ExportXml.php @@ -222,13 +222,13 @@ class ExportXml extends ExportPlugin . '>' . "\n"; if ($exportStruct) { - $result = $dbi->fetchResult( + $result = $dbi->fetchSingleRow( 'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = ' . $dbi->quoteString(Current::$database) . ' LIMIT 1', ); - $dbCollation = $result[0]['DEFAULT_COLLATION_NAME']; - $dbCharset = $result[0]['DEFAULT_CHARACTER_SET_NAME']; + $dbCollation = $result['DEFAULT_COLLATION_NAME']; + $dbCharset = $result['DEFAULT_CHARACTER_SET_NAME']; $head .= '