Skip to content

Commit 30ff7d4

Browse files
Merge pull request #18434 from kamil-tekiela/InsertEdit-pt-3
InsertEdit refactoring - part 3
2 parents 37473d1 + 56136bb commit 30ff7d4

21 files changed

Lines changed: 361 additions & 419 deletions

libraries/classes/ColumnFull.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin;
6+
7+
final class ColumnFull
8+
{
9+
public function __construct(
10+
public readonly string $field,
11+
public readonly string $type,
12+
public readonly string|null $collation,
13+
public readonly bool $isNull,
14+
public readonly string $key,
15+
public readonly string|null $default,
16+
public readonly string $extra,
17+
public readonly string $privileges,
18+
public readonly string $comment,
19+
) {
20+
}
21+
}

libraries/classes/ConfigStorage/Relation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function getDisplayField(string $db, string $table): string
531531
* @param string $db the name of the db to check for
532532
* @param string $table the name of the table to check for
533533
*
534-
* @return mixed[] [column_name] = comment
534+
* @return string[] [column_name] = comment
535535
*/
536536
public function getComments(string $db, string $table = ''): array
537537
{
@@ -544,7 +544,7 @@ public function getComments(string $db, string $table = ''): array
544544
// MySQL native column comments
545545
$columns = $this->dbi->getColumns($db, $table, true);
546546
foreach ($columns as $column) {
547-
if (empty($column['Comment'])) {
547+
if ($column['Comment'] === '') {
548548
continue;
549549
}
550550

libraries/classes/Controllers/Database/DataDictionaryController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __invoke(ServerRequest $request): void
8484
'has_primary_key' => isset($primaryKeys[$row['Field']]),
8585
'type' => $extractedColumnSpec['type'],
8686
'print_type' => $extractedColumnSpec['print_type'],
87-
'is_nullable' => $row['Null'] !== '' && $row['Null'] !== 'NO',
87+
'is_nullable' => $row['Null'] !== 'NO',
8888
'default' => $row['Default'] ?? null,
8989
'comment' => $columnsComments[$row['Field']] ?? '',
9090
'mime' => $mime,

libraries/classes/Controllers/Table/ChangeController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ public function __invoke(ServerRequest $request): void
163163
$GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $whereClauseArray);
164164

165165
$hasBlobField = false;
166-
foreach ($tableColumns as $column) {
167-
if ($this->insertEdit->isColumn($column, ['blob', 'tinyblob', 'mediumblob', 'longblob'])) {
166+
foreach ($tableColumns as $tableColumn) {
167+
if ($this->insertEdit->isColumn($tableColumn->type, ['blob', 'tinyblob', 'mediumblob', 'longblob'])) {
168168
$hasBlobField = true;
169169
break;
170170
}

libraries/classes/Controllers/Table/FindReplaceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function loadTableInfo(): void
9191
// set column name
9292
$this->columnNames[] = $row['Field'];
9393

94-
$type = (string) $row['Type'];
94+
$type = $row['Type'];
9595
// reformat mysql query output
9696
if (strncasecmp($type, 'set', 3) == 0 || strncasecmp($type, 'enum', 4) == 0) {
9797
$type = str_replace(',', ', ', $type);

libraries/classes/Controllers/Table/SearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function loadTableInfo(): void
109109
// set column name
110110
$this->columnNames[] = $row['Field'];
111111

112-
$type = (string) $row['Type'];
112+
$type = $row['Type'];
113113
// before any replacement
114114
$this->originalColumnTypes[] = mb_strtolower($type);
115115
// check whether table contains geometric columns

libraries/classes/Controllers/Table/Structure/ChangeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function displayHtmlForColumnChange(array $selected): void
6161
$fieldsMeta = [];
6262
foreach ($selected as $column) {
6363
$value = $this->dbi->getColumn($GLOBALS['db'], $GLOBALS['table'], $column, true);
64-
if ($value === []) {
64+
if ($value === null) {
6565
$message = Message::error(
6666
__('Failed to get description of column %s!'),
6767
);

libraries/classes/Controllers/Table/ZoomSearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private function loadTableInfo(): void
165165
// set column name
166166
$this->columnNames[] = $row['Field'];
167167

168-
$type = (string) $row['Type'];
168+
$type = $row['Type'];
169169
// before any replacement
170170
$this->originalColumnTypes[] = mb_strtolower($type);
171171
// check whether table contains geometric columns

libraries/classes/Database/CentralColumns.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function syncUniqueColumns(
293293
$hasList = $this->findExistingColNames($db, trim($cols, ','));
294294
foreach ($fieldSelect as $table) {
295295
foreach ($fields[$table] as $def) {
296-
$field = (string) $def['Field'];
296+
$field = $def['Field'];
297297
if (! in_array($field, $hasList)) {
298298
$hasList[] = $field;
299299
$insQuery[] = $this->getInsertQuery($field, $def, $db, $centralListTable);

libraries/classes/DatabaseInterface.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -839,27 +839,37 @@ public function getColumnsFull(
839839
* @param bool $full whether to return full info or only column names
840840
* @psalm-param ConnectionType $connectionType
841841
*
842-
* @return mixed[] flat array description
842+
* @return array{
843+
* Field: string,
844+
* Type: string,
845+
* Collation?: string|null,
846+
* Null:'YES'|'NO',
847+
* Key: string,
848+
* Default: string|null,
849+
* Extra: string,
850+
* Privileges?: string,
851+
* Comment?: string
852+
* }|null
843853
*/
844854
public function getColumn(
845855
string $database,
846856
string $table,
847857
string $column,
848858
bool $full = false,
849859
int $connectionType = Connection::TYPE_USER,
850-
): array {
860+
): array|null {
851861
$sql = QueryGenerator::getColumnsSql(
852862
$database,
853863
$table,
854864
$this->escapeString($this->escapeMysqlWildcards($column)),
855865
$full,
856866
);
857-
/** @var array<string, array> $fields */
867+
/** @var (string|null)[][] $fields */
858868
$fields = $this->fetchResult($sql, 'Field', null, $connectionType);
859869

860870
$columns = $this->attachIndexInfoToColumns($database, $table, $fields);
861871

862-
return array_shift($columns) ?? [];
872+
return array_shift($columns);
863873
}
864874

865875
/**
@@ -870,7 +880,17 @@ public function getColumn(
870880
* @param bool $full whether to return full info or only column names
871881
* @psalm-param ConnectionType $connectionType
872882
*
873-
* @return mixed[][] array indexed by column names
883+
* @return array{
884+
* Field: string,
885+
* Type: string,
886+
* Collation?: string|null,
887+
* Null:'YES'|'NO',
888+
* Key: string,
889+
* Default: string|null,
890+
* Extra: string,
891+
* Privileges?: string,
892+
* Comment?: string
893+
* }[] array indexed by column names
874894
*/
875895
public function getColumns(
876896
string $database,
@@ -879,7 +899,7 @@ public function getColumns(
879899
int $connectionType = Connection::TYPE_USER,
880900
): array {
881901
$sql = QueryGenerator::getColumnsSql($database, $table, null, $full);
882-
/** @var array[] $fields */
902+
/** @var (string|null)[][] $fields */
883903
$fields = $this->fetchResult($sql, 'Field', null, $connectionType);
884904

885905
return $this->attachIndexInfoToColumns($database, $table, $fields);
@@ -888,11 +908,11 @@ public function getColumns(
888908
/**
889909
* Attach index information to the column definition
890910
*
891-
* @param string $database name of database
892-
* @param string $table name of table to retrieve columns from
893-
* @param mixed[][] $fields column array indexed by their names
911+
* @param string $database name of database
912+
* @param string $table name of table to retrieve columns from
913+
* @param (string|null)[][] $fields column array indexed by their names
894914
*
895-
* @return mixed[][] Column defintions with index information
915+
* @return (string|null)[][] Column defintions with index information
896916
*/
897917
private function attachIndexInfoToColumns(
898918
string $database,

0 commit comments

Comments
 (0)