diff --git a/libraries/classes/Database/CentralColumns.php b/libraries/classes/Database/CentralColumns.php index 5215928dfb..bd5ce5e8c6 100644 --- a/libraries/classes/Database/CentralColumns.php +++ b/libraries/classes/Database/CentralColumns.php @@ -13,8 +13,8 @@ use PhpMyAdmin\Template; use PhpMyAdmin\Util; use function __; +use function array_column; use function array_diff; -use function array_keys; use function array_unique; use function array_values; use function bin2hex; @@ -285,14 +285,15 @@ class CentralColumns if ($isTable) { foreach ($field_select as $table) { $fields[$table] = $this->dbi->getColumns($db, $table, true); - foreach (array_keys($fields[$table]) as $field) { + foreach (array_column($fields[$table], 'Field') as $field) { $cols .= "'" . $this->dbi->escapeString($field) . "',"; } } $has_list = $this->findExistingColNames($db, trim($cols, ',')); foreach ($field_select as $table) { - foreach ($fields[$table] as $field => $def) { + foreach ($fields[$table] as $def) { + $field = (string) $def['Field']; if (! in_array($field, $has_list)) { $has_list[] = $field; $insQuery[] = $this->getInsertQuery($field, $def, $db, $central_list_table); diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index c7061e3ab4..877534c3d6 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -866,7 +866,7 @@ class DatabaseInterface implements DbalInterface * @param bool $full whether to return full info or only column names * @psalm-param ConnectionType $connectionType * - * @return array array indexed by column names + * @return array[] array indexed by column names */ public function getColumns( string $database, @@ -880,7 +880,7 @@ class DatabaseInterface implements DbalInterface null, $full, ); - /** @var array $fields */ + /** @var array[] $fields */ $fields = $this->fetchResult($sql, 'Field', null, $connectionType); return $this->attachIndexInfoToColumns($database, $table, $fields); @@ -889,11 +889,11 @@ class DatabaseInterface implements DbalInterface /** * Attach index information to the column definition * - * @param string $database name of database - * @param string $table name of table to retrieve columns from - * @param array $fields column array indexed by their names + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param array[] $fields column array indexed by their names * - * @return array Column defintions with index information + * @return array[] Column defintions with index information */ private function attachIndexInfoToColumns( string $database, @@ -912,7 +912,7 @@ class DatabaseInterface implements DbalInterface } foreach ($indexes as $index) { - if (! $index->hasColumn($field)) { + if (! $index->hasColumn((string) $field)) { continue; } diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index 4e7993c157..3a4c25ab22 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -190,7 +190,7 @@ interface DbalInterface * @param bool $full whether to return full info or only column names * @psalm-param ConnectionType $connectionType * - * @return array array indexed by column names + * @return array[] array indexed by column names */ public function getColumns( string $database, diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 6c78f4f910..34258881fe 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -802,7 +802,7 @@ class Results $sqlMd5 = md5($this->properties['server'] . $this->properties['db'] . $this->properties['sql_query']); $sessionMaxRows = $isLimitedDisplay ? 0 - : $_SESSION['tmpval']['query'][$sqlMd5]['max_rows']; + : (int) $_SESSION['tmpval']['query'][$sqlMd5]['max_rows']; // Following variable are needed for use in isset/empty or // use with array indexes/safe use in the for loop diff --git a/libraries/classes/Index.php b/libraries/classes/Index.php index 8112f11c90..40fe36b18f 100644 --- a/libraries/classes/Index.php +++ b/libraries/classes/Index.php @@ -506,7 +506,7 @@ class Index /** * Returns the columns of the index * - * @return array + * @return IndexColumn[] */ public function getColumns(): array { diff --git a/libraries/classes/Linter.php b/libraries/classes/Linter.php index 9d80da3059..4506ea3fa0 100644 --- a/libraries/classes/Linter.php +++ b/libraries/classes/Linter.php @@ -145,7 +145,7 @@ class Linter // Building the response. foreach ($errors as $error) { // Starting position of the string that caused the error. - [$fromLine, $fromColumn] = static::findLineNumberAndColumn($lines, $error[3]); + [$fromLine, $fromColumn] = static::findLineNumberAndColumn($lines, (int) $error[3]); // Ending position of the string that caused the error. [$toLine, $toColumn] = static::findLineNumberAndColumn( diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php index 89bd557394..ad2a901463 100644 --- a/libraries/classes/Normalization.php +++ b/libraries/classes/Normalization.php @@ -71,7 +71,8 @@ class Normalization $columns = $this->dbi->getColumns($db, $table, true); $type = ''; $selectColHtml = ''; - foreach ($columns as $column => $def) { + foreach ($columns as $def) { + $column = (string) $def['Field']; if (isset($def['Type'])) { $extractedColumnSpec = Util::extractColumnSpec($def['Type']); $type = $extractedColumnSpec['type']; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0a0eb52423..0dea56f2c4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5295,11 +5295,6 @@ parameters: count: 1 path: libraries/classes/Linter.php - - - message: "#^Parameter \\#2 \\$pos of static method PhpMyAdmin\\\\Linter\\:\\:findLineNumberAndColumn\\(\\) expects int, int\\|string\\|null given\\.$#" - count: 1 - path: libraries/classes/Linter.php - - message: "#^Right side of && is always true\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index bc2faaaffb..4fbb707489 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -5005,6 +5005,7 @@ $default + $field $key @@ -5096,6 +5097,7 @@ $defaultValue $defaultValues[$row_num] $extra + $field $has_list[] $key $length @@ -6368,7 +6370,6 @@ $row[$i] $row[$i] - $sessionMaxRows $sortDirection[$index] $sortDirection[$index] $sortDirection[$index] @@ -6572,7 +6573,6 @@ $rel $relationalDisplay orgname)]]]> - $sessionMaxRows $sortDirection[$specialIndex] $sqlQuery $sqlQueryAdd @@ -8358,9 +8358,6 @@ $lines[$line] - - $error[3] - $error[3] diff --git a/test/classes/Database/CentralColumnsTest.php b/test/classes/Database/CentralColumnsTest.php index 981981957a..dc432fcdb3 100644 --- a/test/classes/Database/CentralColumnsTest.php +++ b/test/classes/Database/CentralColumnsTest.php @@ -134,14 +134,17 @@ class CentralColumnsTest extends AbstractTestCase $this->returnValue( [ 'id' => [ + 'Field' => 'id', 'Type' => 'integer', 'Null' => 'NO', ], 'col1' => [ + 'Field' => 'col1', 'Type' => 'varchar(100)', 'Null' => 'YES', ], 'col2' => [ + 'Field' => 'col2', 'Type' => 'DATETIME', 'Null' => 'NO', ], diff --git a/test/classes/NormalizationTest.php b/test/classes/NormalizationTest.php index 3648f80aed..d8e2eb4e21 100644 --- a/test/classes/NormalizationTest.php +++ b/test/classes/NormalizationTest.php @@ -67,9 +67,9 @@ class NormalizationTest extends AbstractTestCase ->will( $this->returnValue( [ - 'id' => ['Type' => 'integer'], - 'col1' => ['Type' => 'varchar(100)'], - 'col2' => ['Type' => 'DATETIME'], + 'id' => ['Field' => 'id', 'Type' => 'integer'], + 'col1' => ['Field' => 'col1', 'Type' => 'varchar(100)'], + 'col2' => ['Field' => 'col2', 'Type' => 'DATETIME'], ], ), );