Skip to content

Commit

Permalink
Redesign CreateAddField::tryColumnCreationQuery()
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Dec 8, 2021
1 parent ce820ed commit ca089b4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
6 changes: 3 additions & 3 deletions libraries/classes/Controllers/Table/AddFieldController.php
Expand Up @@ -107,16 +107,16 @@ public function __invoke(): void

$createAddField = new CreateAddField($this->dbi);

$sqlQuery = $createAddField->getColumnCreationQuery($table);
$sql_query = $createAddField->getColumnCreationQuery($table);

// If there is a request for SQL previewing.
if (isset($_POST['preview_sql'])) {
Core::previewSQL($sqlQuery);
Core::previewSQL($sql_query);

return;
}

[$result, $sql_query] = $createAddField->tryColumnCreationQuery($db, $sqlQuery, $errorUrl);
$result = $createAddField->tryColumnCreationQuery($db, $sql_query, $errorUrl);

if ($result !== true) {
$error_message_html = Generator::mysqlDie('', '', false, $errorUrl, false);
Expand Down
9 changes: 2 additions & 7 deletions libraries/classes/CreateAddField.php
Expand Up @@ -477,14 +477,12 @@ public function getColumnCreationQuery(
* @param string $db current database
* @param string $sqlQuery the query to run
* @param string $errorUrl error page url
*
* @return array
*/
public function tryColumnCreationQuery(
string $db,
string $sqlQuery,
string $errorUrl
): array {
): bool {
// To allow replication, we first select the db to use and then run queries
// on this db.
if (! $this->dbi->selectDb($db)) {
Expand All @@ -496,9 +494,6 @@ public function tryColumnCreationQuery(
);
}

return [
$this->dbi->tryQuery($sqlQuery),
$sqlQuery,
];
return (bool) $this->dbi->tryQuery($sqlQuery);
}
}
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -1890,11 +1890,6 @@ parameters:
count: 1
path: libraries/classes/CreateAddField.php

-
message: "#^Method PhpMyAdmin\\\\CreateAddField\\:\\:tryColumnCreationQuery\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/CreateAddField.php

-
message: "#^Method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:deleteColumnsFromList\\(\\) has parameter \\$field_select with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
3 changes: 1 addition & 2 deletions psalm-baseline.xml
Expand Up @@ -2756,7 +2756,7 @@
</MixedOperand>
</file>
<file src="libraries/classes/Controllers/Table/AddFieldController.php">
<MixedArgument occurrences="12">
<MixedArgument occurrences="11">
<code>$_POST['field_input_transformation'][$fieldindex]</code>
<code>$_POST['field_input_transformation_options'][$fieldindex]</code>
<code>$_POST['field_name'][$fieldindex]</code>
Expand All @@ -2767,7 +2767,6 @@
<code>$db</code>
<code>$mimetype</code>
<code>$regenerate</code>
<code>$sql_query</code>
<code>$table</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="1">
Expand Down

0 comments on commit ca089b4

Please sign in to comment.