Reduce nested ifs

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
This commit is contained in:
Hugues Peccatte 2019-01-12 14:01:59 +01:00
parent dd74c497d9
commit f1e140be05
16 changed files with 128 additions and 160 deletions

View File

@ -19,10 +19,8 @@ require_once ROOT_PATH . 'libraries/common.inc.php';
$relation = new Relation($GLOBALS['dbi']);
// If request for creating the pmadb
if (isset($_POST['create_pmadb'])) {
if ($relation->createPmaDatabase()) {
$relation->fixPmaTables('phpmyadmin');
}
if (isset($_POST['create_pmadb']) && $relation->createPmaDatabase()) {
$relation->fixPmaTables('phpmyadmin');
}
// If request for creating all PMA tables.

View File

@ -130,12 +130,10 @@ $selected_page = null;
if (isset($_GET['query'])) {
$display_page = $designerCommon->getDefaultPage($_GET['db']);
} elseif (! empty($_GET['page'])) {
$display_page = $_GET['page'];
} else {
if (! empty($_GET['page'])) {
$display_page = $_GET['page'];
} else {
$display_page = $designerCommon->getLoadingPage($_GET['db']);
}
$display_page = $designerCommon->getLoadingPage($_GET['db']);
}
if ($display_page != -1) {
$selected_page = $designerCommon->getPageName($display_page);

View File

@ -131,11 +131,9 @@ if (isset($_POST['send_error_report'])
}
} elseif (! empty($_POST['get_settings'])) {
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
} elseif ($_POST['exception_type'] == 'js') {
$response->addHTML($errorReport->getForm());
} else {
if ($_POST['exception_type'] == 'js') {
$response->addHTML($errorReport->getForm());
} else {
// clear previous errors & save new ones.
$GLOBALS['error_handler']->savePreviousErrors();
}
// clear previous errors & save new ones.
$GLOBALS['error_handler']->savePreviousErrors();
}

View File

@ -286,15 +286,13 @@ if ($import_type == 'table') {
$goto = 'db_import.php';
} elseif ($import_type == 'server') {
$goto = 'server_import.php';
} else {
if (empty($goto) || ! preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
if (strlen($table) > 0 && strlen($db) > 0) {
$goto = 'tbl_structure.php';
} elseif (strlen($db) > 0) {
$goto = 'db_structure.php';
} else {
$goto = 'server_sql.php';
}
} elseif (empty($goto) || ! preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) {
if (strlen($table) > 0 && strlen($db) > 0) {
$goto = 'tbl_structure.php';
} elseif (strlen($db) > 0) {
$goto = 'db_structure.php';
} else {
$goto = 'server_sql.php';
}
}
$err_url = $goto . Url::getCommon($urlparams);

View File

@ -235,22 +235,20 @@ if ($server > 0 || count($cfg['Servers']) > 1
include_once ROOT_PATH . 'libraries/check_user_privileges.inc.php';
// Logout for advanced authentication
if ($cfg['Server']['auth_type'] != 'config') {
if ($cfg['ShowChgPassword']) {
$conditional_class = 'ajax';
Core::printListItem(
Util::getImage('s_passwd') . "&nbsp;" . __(
'Change password'
),
'li_change_password',
'user_password.php' . $common_url_query,
null,
null,
'change_password_anchor',
"no_bullets",
$conditional_class
);
}
if (($cfg['Server']['auth_type'] != 'config') && $cfg['ShowChgPassword']) {
$conditional_class = 'ajax';
Core::printListItem(
Util::getImage('s_passwd') . "&nbsp;" . __(
'Change password'
),
'li_change_password',
'user_password.php' . $common_url_query,
null,
null,
'change_password_anchor',
"no_bullets",
$conditional_class
);
} // end if
echo ' <li id="li_select_mysql_collation" class="no_bullets" >';
echo ' <form class="disableAjax" method="post" action="index.php">' , "\n"

View File

@ -568,13 +568,11 @@ class Advisor
);
}
continue;
} else {
if ($ruleLine == -1) {
$errors[] = sprintf(
__('Unexpected characters on line %s.'),
$i + 1
);
}
} elseif ($ruleLine == -1) {
$errors[] = sprintf(
__('Unexpected characters on line %s.'),
$i + 1
);
}
// Reading rule lines

View File

@ -791,17 +791,15 @@ class CentralColumns
$meta = [];
if (! isset($row['col_default']) || $row['col_default'] == '') {
$meta['DefaultType'] = 'NONE';
} elseif ($row['col_default'] == 'CURRENT_TIMESTAMP'
|| $row['col_default'] == 'current_timestamp()'
) {
$meta['DefaultType'] = 'CURRENT_TIMESTAMP';
} elseif ($row['col_default'] == 'NULL') {
$meta['DefaultType'] = $row['col_default'];
} else {
if ($row['col_default'] == 'CURRENT_TIMESTAMP'
|| $row['col_default'] == 'current_timestamp()'
) {
$meta['DefaultType'] = 'CURRENT_TIMESTAMP';
} elseif ($row['col_default'] == 'NULL') {
$meta['DefaultType'] = $row['col_default'];
} else {
$meta['DefaultType'] = 'USER_DEFINED';
$meta['DefaultValue'] = $row['col_default'];
}
$meta['DefaultType'] = 'USER_DEFINED';
$meta['DefaultValue'] = $row['col_default'];
}
$tableHtml .=
'<td class="nowrap" name="col_default">'

View File

@ -48,10 +48,10 @@ class CheckUserPrivileges
$tblname_end_offset = mb_strpos($row, ' TO ');
$tblname_start_offset = false;
if ($__tblname_start_offset = mb_strpos($row, '`.', $db_name_offset)) {
if ($__tblname_start_offset < $tblname_end_offset) {
if (($__tblname_start_offset = mb_strpos($row, '`.', $db_name_offset))
&& $__tblname_start_offset
< $tblname_end_offset) {
$tblname_start_offset = $__tblname_start_offset + 1;
}
}
if (! $tblname_start_offset) {

View File

@ -398,15 +398,13 @@ class Config
$_SESSION['git_location'] = null;
$_SESSION['is_git_revision'] = false;
return false;
} elseif (@is_dir($gitmatch[1])) {
//Detected git external folder location
$git_location = $gitmatch[1];
} else {
if (@is_dir($gitmatch[1])) {
//Detected git external folder location
$git_location = $gitmatch[1];
} else {
$_SESSION['git_location'] = null;
$_SESSION['is_git_revision'] = false;
return false;
}
$_SESSION['git_location'] = null;
$_SESSION['is_git_revision'] = false;
return false;
}
} else {
$_SESSION['git_location'] = null;

View File

@ -1646,10 +1646,8 @@ class DatabaseInterface
}
}
$cfgRelation = $this->relation->getRelationsParam();
if (empty($cfgRelation['db'])) {
if ($GLOBALS['dblist']->databases->exists('phpmyadmin')) {
$this->relation->fixPmaTables('phpmyadmin', false);
}
if (empty($cfgRelation['db']) && $GLOBALS['dblist']->databases->exists('phpmyadmin')) {
$this->relation->fixPmaTables('phpmyadmin', false);
}
}
}

View File

@ -138,45 +138,43 @@ class Export
header('X-pmaPing: Pong');
} // end if
}
} else {
if ($GLOBALS['asfile']) {
if ($GLOBALS['output_charset_conversion']) {
$line = Encoding::convertString(
'utf-8',
$GLOBALS['charset'],
$line
);
}
if ($GLOBALS['save_on_server'] && mb_strlen($line) > 0) {
if (! is_null($GLOBALS['file_handle'])) {
$write_result = @fwrite($GLOBALS['file_handle'], $line);
} else {
$write_result = false;
}
// Here, use strlen rather than mb_strlen to get the length
// in bytes to compare against the number of bytes written.
if (! $write_result
|| $write_result != strlen($line)
) {
$GLOBALS['message'] = Message::error(
__('Insufficient space to save the file %s.')
);
$GLOBALS['message']->addParam($save_filename);
return false;
}
$time_now = time();
if ($time_start >= $time_now + 30) {
$time_start = $time_now;
header('X-pmaPing: Pong');
} // end if
} else {
// We export as file - output normally
echo $line;
}
} else {
// We export as html - replace special chars
echo htmlspecialchars($line);
} elseif ($GLOBALS['asfile']) {
if ($GLOBALS['output_charset_conversion']) {
$line = Encoding::convertString(
'utf-8',
$GLOBALS['charset'],
$line
);
}
if ($GLOBALS['save_on_server'] && mb_strlen($line) > 0) {
if (! is_null($GLOBALS['file_handle'])) {
$write_result = @fwrite($GLOBALS['file_handle'], $line);
} else {
$write_result = false;
}
// Here, use strlen rather than mb_strlen to get the length
// in bytes to compare against the number of bytes written.
if (! $write_result
|| $write_result != strlen($line)
) {
$GLOBALS['message'] = Message::error(
__('Insufficient space to save the file %s.')
);
$GLOBALS['message']->addParam($save_filename);
return false;
}
$time_now = time();
if ($time_start >= $time_now + 30) {
$time_start = $time_now;
header('X-pmaPing: Pong');
} // end if
} else {
// We export as file - output normally
echo $line;
}
} else {
// We export as html - replace special chars
echo htmlspecialchars($line);
}
return true;
}

View File

@ -272,24 +272,20 @@ class Import
if ($go_sql) {
$complete_query .= $import_run_buffer['full'];
$display_query .= $import_run_buffer['full'];
} else {
if (! $sql_query_disabled) {
$sql_query .= $import_run_buffer['full'];
}
} elseif (! $sql_query_disabled) {
$sql_query .= $import_run_buffer['full'];
}
}
// check length of query unless we decided to pass it to sql.php
// (if $run_query is false, we are just displaying so show
// the complete query in the textarea)
if (! $go_sql && $run_query) {
if (! empty($sql_query)) {
if (mb_strlen($sql_query) > 50000
|| $executed_queries > 50
|| $max_sql_len > 1000
) {
$sql_query = '';
$sql_query_disabled = true;
}
if (! $go_sql && $run_query && ! empty($sql_query)) {
if (mb_strlen($sql_query) > 50000
|| $executed_queries > 50
|| $max_sql_len > 1000
) {
$sql_query = '';
$sql_query_disabled = true;
}
}

View File

@ -354,20 +354,18 @@ class Index
}
if (isset($params['Index_choice'])) {
$this->_choice = $params['Index_choice'];
} elseif ('PRIMARY' == $this->_name) {
$this->_choice = 'PRIMARY';
} elseif ('FULLTEXT' == $this->_type) {
$this->_choice = 'FULLTEXT';
$this->_type = '';
} elseif ('SPATIAL' == $this->_type) {
$this->_choice = 'SPATIAL';
$this->_type = '';
} elseif ('0' == $this->_non_unique) {
$this->_choice = 'UNIQUE';
} else {
if ('PRIMARY' == $this->_name) {
$this->_choice = 'PRIMARY';
} elseif ('FULLTEXT' == $this->_type) {
$this->_choice = 'FULLTEXT';
$this->_type = '';
} elseif ('SPATIAL' == $this->_type) {
$this->_choice = 'SPATIAL';
$this->_type = '';
} elseif ('0' == $this->_non_unique) {
$this->_choice = 'UNIQUE';
} else {
$this->_choice = 'INDEX';
}
$this->_choice = 'INDEX';
}
if (isset($params['Key_block_size'])) {
$this->_key_block_size = $params['Key_block_size'];

View File

@ -325,20 +325,18 @@ if (! empty($submit_mult) && ! empty($what)) {
// when dropping a db from server_databases
$GLOBALS['dblist']->databases->build();
}
} else {
if (isset($submit_mult)
&& ($submit_mult == 'sync_unique_columns_central_list'
|| $submit_mult == 'delete_unique_columns_central_list'
|| $submit_mult == 'add_to_central_columns'
|| $submit_mult == 'remove_from_central_columns'
|| $submit_mult == 'make_consistent_with_central_list')
) {
if (isset($centralColsError) && $centralColsError !== true) {
$message = $centralColsError;
} else {
$message = Message::success(__('Success!'));
}
} elseif (isset($submit_mult)
&& ($submit_mult == 'sync_unique_columns_central_list'
|| $submit_mult == 'delete_unique_columns_central_list'
|| $submit_mult == 'add_to_central_columns'
|| $submit_mult == 'remove_from_central_columns'
|| $submit_mult == 'make_consistent_with_central_list')
) {
if (isset($centralColsError) && $centralColsError !== true) {
$message = $centralColsError;
} else {
$message = Message::success(__('No change'));
$message = Message::success(__('Success!'));
}
} else {
$message = Message::success(__('No change'));
}

View File

@ -378,11 +378,9 @@ if (isset($_GET['viewing_mode']) && $_GET['viewing_mode'] == 'db') {
$content = ob_get_contents();
ob_end_clean();
$response->addHTML($content . "\n");
} else {
if (! empty($GLOBALS['message'])) {
$response->addHTML(PhpMyAdmin\Util::getMessage($GLOBALS['message']));
unset($GLOBALS['message']);
}
} elseif (! empty($GLOBALS['message'])) {
$response->addHTML(PhpMyAdmin\Util::getMessage($GLOBALS['message']));
unset($GLOBALS['message']);
}
/**

View File

@ -91,11 +91,9 @@ if (isset($_POST['createview']) || isset($_POST['alterview'])) {
}
}
if (isset($_POST['view']['sql_security'])) {
if (in_array($_POST['view']['sql_security'], $view_security_options)) {
$sql_query .= $sep . ' SQL SECURITY '
. $_POST['view']['sql_security'];
}
if (isset($_POST['view']['sql_security']) && in_array($_POST['view']['sql_security'], $view_security_options)) {
$sql_query .= $sep . ' SQL SECURITY '
. $_POST['view']['sql_security'];
}
$sql_query .= $sep . ' VIEW '