You've already forked phpmyadmin
mirror of
https://github.com/phpmyadmin/phpmyadmin.git
synced 2026-10-28 07:41:55 +03:00
Refactor Plugins\Export\ExportXml::exportDefinitions method
Improve type inference of the parameters. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2545,11 +2545,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/DatabaseInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/DatabaseInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getProtoInfo\\(\\) should return bool\\|int but returns int\\|string\\.$#"
|
||||
count: 1
|
||||
@@ -2680,11 +2675,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Dbal/DbalInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Dbal/DbalInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getTables\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
@@ -5505,11 +5495,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Plugins/Export/ExportXml.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportXml\\:\\:exportDefinitions\\(\\) has parameter \\$names with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Plugins/Export/ExportXml.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportXml\\:\\:getTables\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
|
||||
@@ -5734,10 +5734,12 @@
|
||||
<code>SessionCache::get('mysql_cur_user')</code>
|
||||
<code>reset($columns)</code>
|
||||
</MixedReturnStatement>
|
||||
<MixedReturnTypeCoercion occurrences="4">
|
||||
<MixedReturnTypeCoercion occurrences="6">
|
||||
<code>$result</code>
|
||||
<code>$this->fetchResult($sql, null, 'Field', $link)</code>
|
||||
<code>$this->fetchResult($sql, null, null, $link)</code>
|
||||
<code>string[]</code>
|
||||
<code>string[]</code>
|
||||
</MixedReturnTypeCoercion>
|
||||
<NullableReturnStatement occurrences="2">
|
||||
<code>$user</code>
|
||||
@@ -8663,7 +8665,7 @@
|
||||
</InvalidReturnType>
|
||||
</file>
|
||||
<file src="libraries/classes/Operations.php">
|
||||
<MixedArgument occurrences="35">
|
||||
<MixedArgument occurrences="33">
|
||||
<code>$_POST['comment']</code>
|
||||
<code>$_POST['db_collation'] ?? ''</code>
|
||||
<code>$_POST['new_auto_increment']</code>
|
||||
@@ -8689,12 +8691,10 @@
|
||||
<code>$event_name</code>
|
||||
<code>$foreignTable</code>
|
||||
<code>$foreignTable</code>
|
||||
<code>$function_name</code>
|
||||
<code>$newRowFormat</code>
|
||||
<code>$newRowFormat</code>
|
||||
<code>$old_priv</code>
|
||||
<code>$one_query</code>
|
||||
<code>$procedure_name</code>
|
||||
<code>$this_what ?? 'data'</code>
|
||||
<code>$trigger['create']</code>
|
||||
<code>$view</code>
|
||||
@@ -8756,12 +8756,11 @@
|
||||
<code>$trigger['create']</code>
|
||||
<code>$trigger['create']</code>
|
||||
</MixedArrayAccess>
|
||||
<MixedAssignment occurrences="17">
|
||||
<MixedAssignment occurrences="15">
|
||||
<code>$GLOBALS['auto_increment']</code>
|
||||
<code>$arr</code>
|
||||
<code>$event_name</code>
|
||||
<code>$foreignTable</code>
|
||||
<code>$function_name</code>
|
||||
<code>$newRowFormat</code>
|
||||
<code>$old_priv</code>
|
||||
<code>$old_priv</code>
|
||||
@@ -8770,7 +8769,6 @@
|
||||
<code>$old_priv</code>
|
||||
<code>$old_priv</code>
|
||||
<code>$one_query</code>
|
||||
<code>$procedure_name</code>
|
||||
<code>$this_what</code>
|
||||
<code>$trigger</code>
|
||||
<code>$view</code>
|
||||
@@ -9837,16 +9835,18 @@
|
||||
</PossiblyUndefinedVariable>
|
||||
</file>
|
||||
<file src="libraries/classes/Plugins/Export/ExportXml.php">
|
||||
<MixedArgument occurrences="8">
|
||||
<MixedArgument occurrences="7">
|
||||
<code>$code</code>
|
||||
<code>$col_as</code>
|
||||
<code>$db_charset</code>
|
||||
<code>$db_collation</code>
|
||||
<code>$name</code>
|
||||
<code>$table</code>
|
||||
<code>$table</code>
|
||||
<code>$trigger['name']</code>
|
||||
</MixedArgument>
|
||||
<MixedArgumentTypeCoercion occurrences="1">
|
||||
<code>$events</code>
|
||||
</MixedArgumentTypeCoercion>
|
||||
<MixedArrayAccess occurrences="5">
|
||||
<code>$result[$table][1]</code>
|
||||
<code>$result[0]['DEFAULT_CHARACTER_SET_NAME']</code>
|
||||
@@ -9860,18 +9860,16 @@
|
||||
<MixedArrayTypeCoercion occurrences="1">
|
||||
<code>$result[$table]</code>
|
||||
</MixedArrayTypeCoercion>
|
||||
<MixedAssignment occurrences="8">
|
||||
<MixedAssignment occurrences="7">
|
||||
<code>$GLOBALS['tables']</code>
|
||||
<code>$code</code>
|
||||
<code>$col_as</code>
|
||||
<code>$db_charset</code>
|
||||
<code>$db_collation</code>
|
||||
<code>$name</code>
|
||||
<code>$table</code>
|
||||
<code>$trigger</code>
|
||||
</MixedAssignment>
|
||||
<PossiblyNullArgument occurrences="2">
|
||||
<code>$sql</code>
|
||||
<PossiblyNullArgument occurrences="1">
|
||||
<code>$table_alias</code>
|
||||
</PossiblyNullArgument>
|
||||
<PossiblyNullOperand occurrences="35">
|
||||
|
||||
Reference in New Issue
Block a user