diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b56125c5c6..2d3a2b087a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -9759,12 +9759,6 @@ parameters: count: 3 path: src/Plugins/Export/ExportOds.php - - - message: '#^Binary operation "\." between mixed and '' \('' results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#' identifier: binaryOp.invalid @@ -9780,12 +9774,6 @@ parameters: count: 5 path: src/Plugins/Export/ExportOdt.php - - - message: '#^Cannot access offset ''alias'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Cannot access offset ''columns'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -9795,13 +9783,13 @@ parameters: - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 5 + count: 4 path: src/Plugins/Export/ExportOdt.php - message: '#^Cannot access offset mixed on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 3 + count: 2 path: src/Plugins/Export/ExportOdt.php - @@ -9813,7 +9801,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 5 + count: 4 path: src/Plugins/Export/ExportOdt.php - @@ -9840,6 +9828,12 @@ parameters: count: 2 path: src/Plugins/Export/ExportOdt.php + - + message: '#^Parameter \#3 \$table of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:getTableAlias\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Plugins/Export/ExportOdt.php + - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: @@ -9933,7 +9927,7 @@ parameters: - message: '#^Cannot access offset ''alias'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 4 + count: 2 path: src/Plugins/Export/ExportSql.php - @@ -9945,7 +9939,7 @@ parameters: - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 11 + count: 10 path: src/Plugins/Export/ExportSql.php - @@ -9963,7 +9957,7 @@ parameters: - message: '#^Cannot access offset string\|null on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 7 + count: 6 path: src/Plugins/Export/ExportSql.php - @@ -10011,7 +10005,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 24 + count: 21 path: src/Plugins/Export/ExportSql.php - @@ -10092,6 +10086,12 @@ parameters: count: 3 path: src/Plugins/Export/ExportSql.php + - + message: '#^Parameter \#3 \$table of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:getTableAlias\(\) expects string, string\|null given\.$#' + identifier: argument.type + count: 1 + path: src/Plugins/Export/ExportSql.php + - message: '#^Property PhpMyAdmin\\SqlParser\\Components\\CreateDefinition\:\:\$name \(string\|null\) does not accept mixed\.$#' identifier: assign.propertyType @@ -10605,12 +10605,6 @@ parameters: count: 2 path: src/Plugins/ExportPlugin.php - - - message: '#^Binary operation "\." between mixed and '' \('' results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/Plugins/ExportPlugin.php - - message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#' identifier: binaryOp.invalid @@ -10620,7 +10614,7 @@ parameters: - message: '#^Cannot access offset ''alias'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 5 + count: 4 path: src/Plugins/ExportPlugin.php - @@ -10632,13 +10626,13 @@ parameters: - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 4 + count: 3 path: src/Plugins/ExportPlugin.php - message: '#^Cannot access offset mixed on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible - count: 3 + count: 2 path: src/Plugins/ExportPlugin.php - @@ -10656,7 +10650,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 9 + count: 8 path: src/Plugins/ExportPlugin.php - @@ -10671,6 +10665,18 @@ parameters: count: 3 path: src/Plugins/ExportPlugin.php + - + message: '#^Method PhpMyAdmin\\Plugins\\ExportPlugin\:\:getDbAlias\(\) should return string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Plugins/ExportPlugin.php + + - + message: '#^Method PhpMyAdmin\\Plugins\\ExportPlugin\:\:getTableAlias\(\) should return string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Plugins/ExportPlugin.php + - message: '#^Only booleans are allowed in an if condition, array\|false given\.$#' identifier: if.condNotBoolean @@ -10678,14 +10684,8 @@ parameters: path: src/Plugins/ExportPlugin.php - - message: '#^Parameter &\$db by\-ref type of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:initAlias\(\) expects string, mixed given\.$#' - identifier: parameterByRef.type - count: 1 - path: src/Plugins/ExportPlugin.php - - - - message: '#^Parameter &\$table by\-ref type of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:initAlias\(\) expects string, mixed given\.$#' - identifier: parameterByRef.type + message: '#^Parameter \#3 \$table of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:getTableAlias\(\) expects string, mixed given\.$#' + identifier: argument.type count: 1 path: src/Plugins/ExportPlugin.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 77e79908be..a8ec00c7fe 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6201,12 +6201,12 @@ + - @@ -6217,11 +6217,9 @@ - - @@ -6314,12 +6312,8 @@ name]]> references->table->table]]> - - - name->database]]> - name->table]]> table->table]]> @@ -6333,10 +6327,8 @@ + - - - @@ -6372,7 +6364,6 @@ selectedServer['port'])]]> fields)]]> name->database)]]> - name->database)]]> table->database)]]> @@ -6723,6 +6714,9 @@ + + + @@ -6735,7 +6729,6 @@ - @@ -6743,20 +6736,20 @@ - - - - + + + + diff --git a/src/Plugins/Export/ExportCodegen.php b/src/Plugins/Export/ExportCodegen.php index 506c69e48d..b1d8ff0cb9 100644 --- a/src/Plugins/Export/ExportCodegen.php +++ b/src/Plugins/Export/ExportCodegen.php @@ -186,9 +186,8 @@ class ExportCodegen extends ExportPlugin */ private function handleNHibernateCSBody(string $db, string $table, array $aliases = []): string { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $result = DatabaseInterface::getInstance()->query( sprintf( @@ -291,9 +290,8 @@ class ExportCodegen extends ExportPlugin string $table, array $aliases = [], ): string { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $lines = []; $lines[] = ''; $lines[] = 'initAlias($aliases, $dbAlias, $tableAlias); - $dbi = DatabaseInterface::getInstance(); /** * Gets the data from the database diff --git a/src/Plugins/Export/ExportExcel.php b/src/Plugins/Export/ExportExcel.php index 73531600f3..713157ea40 100644 --- a/src/Plugins/Export/ExportExcel.php +++ b/src/Plugins/Export/ExportExcel.php @@ -179,10 +179,6 @@ class ExportExcel extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); - $dbi = DatabaseInterface::getInstance(); /** * Gets the data from the database diff --git a/src/Plugins/Export/ExportHtmlword.php b/src/Plugins/Export/ExportHtmlword.php index eb6677cc4f..bdc6ef4876 100644 --- a/src/Plugins/Export/ExportHtmlword.php +++ b/src/Plugins/Export/ExportHtmlword.php @@ -182,9 +182,7 @@ class ExportHtmlword extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); if ( ! $this->export->outputHandler( @@ -474,9 +472,7 @@ class ExportHtmlword extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dump = ''; diff --git a/src/Plugins/Export/ExportJson.php b/src/Plugins/Export/ExportJson.php index 74c4ffe461..b324f43e9a 100644 --- a/src/Plugins/Export/ExportJson.php +++ b/src/Plugins/Export/ExportJson.php @@ -182,9 +182,8 @@ class ExportJson extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); if (! $this->first) { if (! $this->export->outputHandler(',')) { diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php index 860280b25f..ffc5390166 100644 --- a/src/Plugins/Export/ExportLatex.php +++ b/src/Plugins/Export/ExportLatex.php @@ -298,9 +298,8 @@ class ExportLatex extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dbi = DatabaseInterface::getInstance(); $result = $dbi->tryQuery($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); @@ -437,9 +436,8 @@ class ExportLatex extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $relationParameters = $this->relation->getRelationParameters(); diff --git a/src/Plugins/Export/ExportMediawiki.php b/src/Plugins/Export/ExportMediawiki.php index f7fc49385a..2aadfb96ee 100644 --- a/src/Plugins/Export/ExportMediawiki.php +++ b/src/Plugins/Export/ExportMediawiki.php @@ -152,9 +152,7 @@ class ExportMediawiki extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $output = ''; if ($exportMode === 'create_table') { @@ -236,9 +234,7 @@ class ExportMediawiki extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); // Print data comment $output = $this->exportComment( diff --git a/src/Plugins/Export/ExportOds.php b/src/Plugins/Export/ExportOds.php index 3b9e0d77ab..cd5b57a3b5 100644 --- a/src/Plugins/Export/ExportOds.php +++ b/src/Plugins/Export/ExportOds.php @@ -201,9 +201,7 @@ class ExportOds extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dbi = DatabaseInterface::getInstance(); // Gets the data from the database $result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); diff --git a/src/Plugins/Export/ExportOdt.php b/src/Plugins/Export/ExportOdt.php index ee48895edf..18e32ed499 100644 --- a/src/Plugins/Export/ExportOdt.php +++ b/src/Plugins/Export/ExportOdt.php @@ -229,9 +229,7 @@ class ExportOdt extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dbi = DatabaseInterface::getInstance(); // Gets the data from the database $result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); @@ -341,9 +339,7 @@ class ExportOdt extends ExportPlugin */ public function getTableDefStandIn(string $db, string $view, array $aliases = []): string { - $dbAlias = $db; - $viewAlias = $view; - $this->initAlias($aliases, $dbAlias, $viewAlias); + $viewAlias = $this->getTableAlias($aliases, $db, $view); $dbi = DatabaseInterface::getInstance(); /** * Gets fields properties @@ -399,9 +395,7 @@ class ExportOdt extends ExportPlugin */ public function getTableDef(string $db, string $table, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $relationParameters = $this->relation->getRelationParameters(); @@ -488,9 +482,7 @@ class ExportOdt extends ExportPlugin $rfield = $aliases[$db]['tables'][$rtable]['columns'][$rfield]; } - if (! empty($aliases[$db]['tables'][$rtable]['alias'])) { - $rtable = $aliases[$db]['tables'][$rtable]['alias']; - } + $rtable = $this->getTableAlias($aliases, $db, $rtable); $relation = htmlspecialchars($rtable . ' (' . $rfield . ')'); $this->buffer .= '' @@ -606,9 +598,7 @@ class ExportOdt extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); switch ($exportMode) { case 'create_table': $this->buffer .= 'initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $pdf = $this->getPdf(); $pdf->setCurrentDb($db); $pdf->setCurrentTable($table); @@ -221,10 +220,9 @@ class ExportPdf extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; $purpose = ''; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $pdf = $this->getPdf(); // getting purpose to show at top switch ($exportMode) { diff --git a/src/Plugins/Export/ExportPhparray.php b/src/Plugins/Export/ExportPhparray.php index 40f32460e4..f4fc312dbf 100644 --- a/src/Plugins/Export/ExportPhparray.php +++ b/src/Plugins/Export/ExportPhparray.php @@ -153,9 +153,8 @@ class ExportPhparray extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dbi = DatabaseInterface::getInstance(); $result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); diff --git a/src/Plugins/Export/ExportSql.php b/src/Plugins/Export/ExportSql.php index e4bf12f58f..f03c40f706 100644 --- a/src/Plugins/Export/ExportSql.php +++ b/src/Plugins/Export/ExportSql.php @@ -1249,9 +1249,7 @@ class ExportSql extends ExportPlugin */ public function getTableDefStandIn(string $db, string $view, array $aliases = []): string { - $dbAlias = $db; - $viewAlias = $view; - $this->initAlias($aliases, $dbAlias, $viewAlias); + $viewAlias = $this->getTableAlias($aliases, $db, $view); $createQuery = ''; if ($this->dropTable) { $createQuery .= 'DROP VIEW IF EXISTS ' @@ -1294,9 +1292,7 @@ class ExportSql extends ExportPlugin string $view, array $aliases = [], ): string { - $dbAlias = $db; - $viewAlias = $view; - $this->initAlias($aliases, $dbAlias, $viewAlias); + $viewAlias = $this->getTableAlias($aliases, $db, $view); $createQuery = 'CREATE TABLE'; if ($this->ifNotExists) { $createQuery .= ' IF NOT EXISTS '; @@ -1374,9 +1370,7 @@ class ExportSql extends ExportPlugin bool $updateIndexesIncrements = true, array $aliases = [], ): string { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $schemaCreate = $this->getTableStatus($db, $table); @@ -1738,9 +1732,7 @@ class ExportSql extends ExportPlugin */ private function getTableComments(string $db, string $table, array $aliases = []): string { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $relationParameters = $this->relation->getRelationParameters(); @@ -1881,9 +1873,7 @@ class ExportSql extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $formattedTableName = Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes); $dump = $this->possibleCRLF() . $this->exportComment(str_repeat('-', 56)) @@ -2027,9 +2017,7 @@ class ExportSql extends ExportPlugin return true; } - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $formattedTableName = Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes); @@ -2404,9 +2392,6 @@ class ExportSql extends ExportPlugin ): string { $flag = false; - /** - * The parser of this query. - */ $parser = new Parser($delimiter === '' ? $sqlQuery : 'DELIMITER ' . $delimiter . "\n" . $sqlQuery); if (empty($parser->statements[0])) { @@ -2420,39 +2405,19 @@ class ExportSql extends ExportPlugin */ $statement = $parser->statements[0]; - /** - * Old database name. - */ $oldDatabase = $db; // Replacing aliases in `CREATE TABLE` statement. if ($statement->options->has('TABLE')) { - // Extracting the name of the old database and table from the - // statement to make sure the parameters are correct. - if (! empty($statement->name->database)) { - $oldDatabase = $statement->name->database; - } - - /** - * Old table name. - */ $oldTable = $statement->name->table; - // Finding the aliased database name. - // The database might be empty so we have to add a few checks. $newDatabase = null; if (! empty($statement->name->database)) { - $newDatabase = $statement->name->database; - if (! empty($aliases[$oldDatabase]['alias'])) { - $newDatabase = $aliases[$oldDatabase]['alias']; - } + $oldDatabase = $statement->name->database; + $newDatabase = $this->getDbAlias($aliases, $oldDatabase); } - // Finding the aliases table name. - $newTable = $oldTable; - if (! empty($aliases[$oldDatabase]['tables'][$oldTable]['alias'])) { - $newTable = $aliases[$oldDatabase]['tables'][$oldTable]['alias']; - } + $newTable = $this->getTableAlias($aliases, $oldDatabase, $oldTable); // Replacing new values. if ($statement->name->database !== $newDatabase || $statement->name->table !== $newTable) { @@ -2522,13 +2487,11 @@ class ExportSql extends ExportPlugin $oldDatabase = $statement->table->database; } - /** - * Old table name. - */ $oldTable = $statement->table->table; + $newTable = $this->getTableAlias($aliases, $oldDatabase, $oldTable); - if (! empty($aliases[$oldDatabase]['tables'][$oldTable]['alias'])) { - $statement->table->table = $aliases[$oldDatabase]['tables'][$oldTable]['alias']; + if ($newTable !== $oldTable) { + $statement->table->table = $newTable; $statement->table->expr = ''; // Force rebuild. $flag = true; } diff --git a/src/Plugins/Export/ExportTexytext.php b/src/Plugins/Export/ExportTexytext.php index bcaba86abf..7b0a2bfa33 100644 --- a/src/Plugins/Export/ExportTexytext.php +++ b/src/Plugins/Export/ExportTexytext.php @@ -167,9 +167,7 @@ class ExportTexytext extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); if ( ! $this->export->outputHandler( @@ -448,9 +446,7 @@ class ExportTexytext extends ExportPlugin */ public function exportStructure(string $db, string $table, string $exportMode, array $aliases = []): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dump = ''; switch ($exportMode) { diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php index 8411a6e5d7..07d534d622 100644 --- a/src/Plugins/Export/ExportXml.php +++ b/src/Plugins/Export/ExportXml.php @@ -420,9 +420,7 @@ class ExportXml extends ExportPlugin return true; } - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $tableAlias = $this->getTableAlias($aliases, $db, $table); if ($this->exportContents) { $result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); diff --git a/src/Plugins/Export/ExportYaml.php b/src/Plugins/Export/ExportYaml.php index c330eceb65..57da137211 100644 --- a/src/Plugins/Export/ExportYaml.php +++ b/src/Plugins/Export/ExportYaml.php @@ -128,9 +128,8 @@ class ExportYaml extends ExportPlugin string $sqlQuery, array $aliases = [], ): bool { - $dbAlias = $db; - $tableAlias = $table; - $this->initAlias($aliases, $dbAlias, $tableAlias); + $dbAlias = $this->getDbAlias($aliases, $db); + $tableAlias = $this->getTableAlias($aliases, $db, $table); $dbi = DatabaseInterface::getInstance(); $result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED); diff --git a/src/Plugins/ExportPlugin.php b/src/Plugins/ExportPlugin.php index 0706f3fdfb..b144fa3cab 100644 --- a/src/Plugins/ExportPlugin.php +++ b/src/Plugins/ExportPlugin.php @@ -201,24 +201,16 @@ abstract class ExportPlugin implements Plugin * below methods unless you want to override them. */ - /** - * Initialize aliases - * - * @param mixed[] $aliases Alias information for db/table/column - * @param string $db the database - * @param string $table the table - */ - public function initAlias(array $aliases, string &$db, string &$table): void + /** @param mixed[] $aliases Alias information for db/table/columns */ + public function getDbAlias(array $aliases, string $db): string { - if (! empty($aliases[$db]['tables'][$table]['alias'])) { - $table = $aliases[$db]['tables'][$table]['alias']; - } + return ! empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : $db; + } - if (empty($aliases[$db]['alias'])) { - return; - } - - $db = $aliases[$db]['alias']; + /** @param mixed[] $aliases Alias information for db/table/columns */ + public function getTableAlias(array $aliases, string $db, string $table): string + { + return ! empty($aliases[$db]['tables'][$table]['alias']) ? $aliases[$db]['tables'][$table]['alias'] : $table; } /** @@ -310,9 +302,7 @@ abstract class ExportPlugin implements Plugin $ffield = $aliases[$db]['tables'][$ftable]['columns'][$ffield]; } - if (! empty($aliases[$db]['tables'][$ftable]['alias'])) { - $ftable = $aliases[$db]['tables'][$ftable]['alias']; - } + $ftable = $this->getTableAlias($aliases, $db, $ftable); return $ftable . ' (' . $ffield . ')'; } diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index a5efafaa95..8409d8ac31 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -1324,21 +1324,24 @@ class ExportSqlTest extends AbstractTestCase $db = 'a'; $table = ''; - $this->object->initAlias($aliases, $db, $table); + $table = $this->object->getTableAlias($aliases, $db, $table); + $db = $this->object->getDbAlias($aliases, $db); self::assertSame('aliastest', $db); self::assertSame('', $table); $db = 'foo'; $table = 'qwerty'; - $this->object->initAlias($aliases, $db, $table); + $table = $this->object->getTableAlias($aliases, $db, $table); + $db = $this->object->getDbAlias($aliases, $db); self::assertSame('foo', $db); self::assertSame('qwerty', $table); $db = 'a'; $table = 'foo'; - $this->object->initAlias($aliases, $db, $table); + $table = $this->object->getTableAlias($aliases, $db, $table); + $db = $this->object->getDbAlias($aliases, $db); self::assertSame('aliastest', $db); self::assertSame('qwerty', $table); }