Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce nested ifs #14855

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions chk_rel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
$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.
Expand Down
8 changes: 3 additions & 5 deletions db_designer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@

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);
Expand Down
10 changes: 4 additions & 6 deletions error_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@
}
} 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();
}
16 changes: 7 additions & 9 deletions import.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,13 @@
$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);
Expand Down
30 changes: 14 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,20 @@
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') . " " . __(
'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') . " " . __(
'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"
Expand Down
12 changes: 5 additions & 7 deletions libraries/classes/Advisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,11 @@ public static function parseRulesFile(): array
);
}
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
Expand Down
18 changes: 8 additions & 10 deletions libraries/classes/CentralColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,15 @@ private function getHtmlForEditTableRow(array $row, int $row_num): string
$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">'
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/CheckUserPrivileges.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function getItemsFromShowGrantsRow(string $row): array
$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) {
Expand Down
14 changes: 6 additions & 8 deletions libraries/classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,13 @@ public function isGitRevision(&$git_location = null): bool
$_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;
Expand Down
6 changes: 2 additions & 4 deletions libraries/classes/DatabaseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,10 +1646,8 @@ public function postConnectControl(): void
}
}
$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);
}
}
}
Expand Down
68 changes: 33 additions & 35 deletions libraries/classes/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,45 +138,43 @@ public function outputHandler(?string $line): bool
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
} 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 {
// We export as file - output normally
echo $line;
$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 html - replace special chars
echo htmlspecialchars($line);
// We export as file - output normally
echo $line;
}
} else {
// We export as html - replace special chars
echo htmlspecialchars($line);
}
return true;
}
Expand Down
22 changes: 9 additions & 13 deletions libraries/classes/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,20 @@ public function runQuery(
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;
}
}

Expand Down
24 changes: 11 additions & 13 deletions libraries/classes/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,18 @@ public function set(array $params)
}
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'];
Expand Down
26 changes: 12 additions & 14 deletions libraries/mult_submits.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,18 @@
// 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'));
}
8 changes: 3 additions & 5 deletions server_privileges.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,9 @@
$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']);
}

/**
Expand Down