diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-11 02:03:39 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-11 02:03:39 +0300 |
commit | 1cf2d303c00567494cf11c250b89648eebe593bc (patch) | |
tree | 703313d78c4df581559c1eb40c83225db0e141e2 /libraries/classes | |
parent | a8421efd56011cb2917f358ca26bea2a7168c230 (diff) |
Refactor Plugins\Export\ExportXml::exportDefinitions method
Improve type inference of the parameters.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries/classes')
-rw-r--r-- | libraries/classes/DatabaseInterface.php | 2 | ||||
-rw-r--r-- | libraries/classes/Dbal/DbalInterface.php | 2 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportXml.php | 69 |
3 files changed, 34 insertions, 39 deletions
diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index cec845d427..f2bccb3eb4 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -1472,7 +1472,7 @@ class DatabaseInterface implements DbalInterface * @param string $which PROCEDURE | FUNCTION * @param int $link link type * - * @return array the procedure names or function names + * @return string[] the procedure names or function names */ public function getProceduresOrFunctions( string $db, diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index ebd462b6de..8b54935871 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -436,7 +436,7 @@ interface DbalInterface * @param string $which PROCEDURE | FUNCTION * @param int $link link type * - * @return array the procedure names or function names + * @return string[] the procedure names or function names */ public function getProceduresOrFunctions( string $db, diff --git a/libraries/classes/Plugins/Export/ExportXml.php b/libraries/classes/Plugins/Export/ExportXml.php index 3241eaf2bc..349fe0abc2 100644 --- a/libraries/classes/Plugins/Export/ExportXml.php +++ b/libraries/classes/Plugins/Export/ExportXml.php @@ -148,51 +148,38 @@ class ExportXml extends ExportPlugin } /** - * Generates output for SQL defintions of routines + * Generates output for SQL definitions. * - * @param string $db Database name - * @param string $type Item type to be used in XML output - * @param string $dbitype Item type used in DBI queries + * @param string $db Database name + * @param string $type Item type to be used in XML output + * @param string[] $names Names of items to export + * @psalm-param 'event'|'function'|'procedure' $type * * @return string XML with definitions */ - private function exportRoutinesDefinition($db, $type, $dbitype) - { - // Export routines - $routines = $GLOBALS['dbi']->getProceduresOrFunctions($db, $dbitype); - - return $this->exportDefinitions($db, $type, $dbitype, $routines); - } - - /** - * Generates output for SQL defintions - * - * @param string $db Database name - * @param string $type Item type to be used in XML output - * @param string $dbitype Item type used in DBI queries - * @param array $names Names of items to export - * - * @return string XML with definitions - */ - private function exportDefinitions($db, $type, $dbitype, array $names) + private function exportDefinitions(string $db, string $type, array $names): string { $GLOBALS['crlf'] = $GLOBALS['crlf'] ?? null; $head = ''; - if ($names) { - foreach ($names as $name) { - $head .= ' <pma:' . $type . ' name="' - . htmlspecialchars($name) . '">' . $GLOBALS['crlf']; + foreach ($names as $name) { + $head .= ' <pma:' . $type . ' name="' . htmlspecialchars($name) . '">' . $GLOBALS['crlf']; - // Do some formatting - $sql = $GLOBALS['dbi']->getDefinition($db, $dbitype, $name); - $sql = htmlspecialchars(rtrim($sql)); - $sql = str_replace("\n", "\n ", $sql); - - $head .= ' ' . $sql . $GLOBALS['crlf']; - $head .= ' </pma:' . $type . '>' . $GLOBALS['crlf']; + if ($type === 'function') { + $definition = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $name); + } elseif ($type === 'procedure') { + $definition = $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $name); + } else { + $definition = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $name); } + + // Do some formatting + $sql = htmlspecialchars(rtrim((string) $definition)); + $sql = str_replace("\n", "\n ", $sql); + + $head .= ' ' . $sql . $GLOBALS['crlf']; + $head .= ' </pma:' . $type . '>' . $GLOBALS['crlf']; } return $head; @@ -331,11 +318,19 @@ class ExportXml extends ExportPlugin } if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) { - $head .= $this->exportRoutinesDefinition($GLOBALS['db'], 'function', 'FUNCTION'); + $head .= $this->exportDefinitions( + $GLOBALS['db'], + 'function', + $GLOBALS['dbi']->getProceduresOrFunctions($GLOBALS['db'], 'FUNCTION') + ); } if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) { - $head .= $this->exportRoutinesDefinition($GLOBALS['db'], 'procedure', 'PROCEDURE'); + $head .= $this->exportDefinitions( + $GLOBALS['db'], + 'procedure', + $GLOBALS['dbi']->getProceduresOrFunctions($GLOBALS['db'], 'PROCEDURE') + ); } if (isset($GLOBALS['xml_export_events']) && $GLOBALS['xml_export_events']) { @@ -345,7 +340,7 @@ class ExportXml extends ExportPlugin . "WHERE EVENT_SCHEMA='" . $GLOBALS['dbi']->escapeString($GLOBALS['db']) . "'" ); - $head .= $this->exportDefinitions($GLOBALS['db'], 'event', 'EVENT', $events); + $head .= $this->exportDefinitions($GLOBALS['db'], 'event', $events); } unset($result); |