Merge pull request #18279 from kamil-tekiela/fix-param-issues

Fix param type issues
This commit is contained in:
Maurício Meneghini Fauth 2023-03-19 19:29:35 -03:00 committed by GitHub
commit 4d612b0175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 25 additions and 28 deletions

View File

@ -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);

View File

@ -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<string, 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<string, 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<string, 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<string, 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;
}

View File

@ -190,7 +190,7 @@ interface DbalInterface
* @param bool $full whether to return full info or only column names
* @psalm-param ConnectionType $connectionType
*
* @return array<string, array> array indexed by column names
* @return array[] array indexed by column names
*/
public function getColumns(
string $database,

View File

@ -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

View File

@ -506,7 +506,7 @@ class Index
/**
* Returns the columns of the index
*
* @return array<string, IndexColumn>
* @return IndexColumn[]
*/
public function getColumns(): array
{

View File

@ -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(

View File

@ -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'];

View File

@ -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

View File

@ -5005,6 +5005,7 @@
<code><![CDATA[$def['Type']]]></code>
<code>$default</code>
<code><![CDATA[$extracted_columnspec['attribute']]]></code>
<code>$field</code>
<code>$key</code>
<code><![CDATA[$meta['DefaultValue']]]></code>
<code><![CDATA[$meta['DefaultValue']]]></code>
@ -5096,6 +5097,7 @@
<code>$defaultValue</code>
<code>$defaultValues[$row_num]</code>
<code>$extra</code>
<code>$field</code>
<code>$has_list[]</code>
<code>$key</code>
<code>$length</code>
@ -6368,7 +6370,6 @@
<code><![CDATA[$rel['foreign_table']]]></code>
<code>$row[$i]</code>
<code>$row[$i]</code>
<code>$sessionMaxRows</code>
<code>$sortDirection[$index]</code>
<code>$sortDirection[$index]</code>
<code>$sortDirection[$index]</code>
@ -6572,7 +6573,6 @@
<code>$rel</code>
<code>$relationalDisplay</code>
<code><![CDATA[$rowInfo[mb_strtolower($fieldsMeta[$m]->orgname)]]]></code>
<code>$sessionMaxRows</code>
<code>$sortDirection[$specialIndex]</code>
<code>$sqlQuery</code>
<code>$sqlQueryAdd</code>
@ -8358,9 +8358,6 @@
<MixedOperand>
<code>$lines[$line]</code>
</MixedOperand>
<PossiblyInvalidArgument>
<code>$error[3]</code>
</PossiblyInvalidArgument>
<PossiblyNullOperand>
<code>$error[3]</code>
</PossiblyNullOperand>

View File

@ -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',
],

View File

@ -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'],
],
),
);