Remove some else conditions by using early exits or moving code

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-04-29 00:46:24 +02:00
parent 75c148b885
commit db01d6a9da
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
9 changed files with 98 additions and 91 deletions

View File

@ -117,12 +117,11 @@ OpenID: <input type="text" name="identifier"><br>
}
/* Grab identifier */
$identifier = null;
if (isset($_POST['identifier']) && is_string($_POST['identifier'])) {
$identifier = $_POST['identifier'];
} elseif (isset($_SESSION['identifier']) && is_string($_SESSION['identifier'])) {
$identifier = $_SESSION['identifier'];
} else {
$identifier = null;
}
/* Create OpenID object */
@ -150,7 +149,7 @@ if (isset($_POST['start'])) {
if (! count($_POST)) {
[, $queryString] = explode('?', $_SERVER['REQUEST_URI']);
} else {
// I hate php sometimes
// Fetch the raw query body
$queryString = file_get_contents('php://input');
}

View File

@ -211,7 +211,7 @@ class Bookmark
*
* @param string $user Current user
*
* @return array|bool the bookmark parameters for the current user
* @return array|false the bookmark parameters for the current user
*
* @access public
*/
@ -228,16 +228,14 @@ class Bookmark
$relation = new Relation($dbi);
$cfgRelation = $relation->getRelationsParam();
if ($cfgRelation['bookmarkwork']) {
$cfgBookmark = [
return [
'user' => $user,
'db' => $cfgRelation['db'],
'table' => $cfgRelation['bookmark'],
];
} else {
$cfgBookmark = false;
}
return $cfgBookmark;
return false;
}
/**

View File

@ -369,8 +369,10 @@ class CheckUserPrivileges
$GLOBALS['col_priv'] = true;
$GLOBALS['table_priv'] = true;
$GLOBALS['proc_priv'] = true;
} else {
$this->analyseShowGrant();
return;
}
$this->analyseShowGrant();
}
}

View File

@ -193,10 +193,9 @@ class Config
*/
public function checkClient(): void
{
$HTTP_USER_AGENT = '';
if (Core::getenv('HTTP_USER_AGENT')) {
$HTTP_USER_AGENT = Core::getenv('HTTP_USER_AGENT');
} else {
$HTTP_USER_AGENT = '';
}
// 1. Platform
@ -334,12 +333,12 @@ class Config
$gd_nfo = gd_info();
if (mb_strstr($gd_nfo['GD Version'], '2.')) {
$this->set('PMA_IS_GD2', 1);
} else {
$this->set('PMA_IS_GD2', 0);
return;
}
} else {
$this->set('PMA_IS_GD2', 0);
}
$this->set('PMA_IS_GD2', 0);
}
/**
@ -355,9 +354,11 @@ class Config
&& stripos(Core::getenv('SERVER_SOFTWARE'), 'IIS') !== false
) {
$this->set('PMA_IS_IIS', 1);
} else {
$this->set('PMA_IS_IIS', 0);
return;
}
$this->set('PMA_IS_IIS', 0);
}
/**
@ -1378,35 +1379,37 @@ class Config
if (! isset($this->settings['Servers']) || count($this->settings['Servers']) === 0) {
// No server => create one with defaults
$this->settings['Servers'] = [1 => $this->defaultServer];
} else {
// We have server(s) => apply default configuration
$new_servers = [];
foreach ($this->settings['Servers'] as $server_index => $each_server) {
// Detect wrong configuration
if (! is_int($server_index) || $server_index < 1) {
trigger_error(
sprintf(__('Invalid server index: %s'), $server_index),
E_USER_ERROR
);
}
return;
}
$each_server = array_merge($this->defaultServer, $each_server);
// We have server(s) => apply default configuration
$new_servers = [];
// Final solution to bug #582890
// If we are using a socket connection
// and there is nothing in the verbose server name
// or the host field, then generate a name for the server
// in the form of "Server 2", localized of course!
if (empty($each_server['host']) && empty($each_server['verbose'])) {
$each_server['verbose'] = sprintf(__('Server %d'), $server_index);
}
$new_servers[$server_index] = $each_server;
foreach ($this->settings['Servers'] as $server_index => $each_server) {
// Detect wrong configuration
if (! is_int($server_index) || $server_index < 1) {
trigger_error(
sprintf(__('Invalid server index: %s'), $server_index),
E_USER_ERROR
);
}
$this->settings['Servers'] = $new_servers;
$each_server = array_merge($this->defaultServer, $each_server);
// Final solution to bug #582890
// If we are using a socket connection
// and there is nothing in the verbose server name
// or the host field, then generate a name for the server
// in the form of "Server 2", localized of course!
if (empty($each_server['host']) && empty($each_server['verbose'])) {
$each_server['verbose'] = sprintf(__('Server %d'), $server_index);
}
$new_servers[$server_index] = $each_server;
}
$this->settings['Servers'] = $new_servers;
}
/**

View File

@ -702,20 +702,24 @@ class StructureController extends AbstractController
'sql_data',
$this->template->render('preview_sql', ['query_data' => $sql_query])
);
} else { // move column
$this->dbi->tryQuery($sql_query);
$tmp_error = $this->dbi->getError();
if (is_string($tmp_error)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error($tmp_error));
} else {
$message = Message::success(
__('The columns have been moved successfully.')
);
$this->response->addJSON('message', $message);
$this->response->addJSON('columns', $column_names);
}
return;
}
$this->dbi->tryQuery($sql_query);
$tmp_error = $this->dbi->getError();
if (is_string($tmp_error)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error($tmp_error));
return;
}
$message = Message::success(
__('The columns have been moved successfully.')
);
$this->response->addJSON('message', $message);
$this->response->addJSON('columns', $column_names);
}
/**
@ -848,11 +852,8 @@ class StructureController extends AbstractController
$openPos + 1,
$closePos - ($openPos + 1)
));
if (isset($stmt->partitionsNum)) {
$count = $stmt->partitionsNum;
} else {
$count = count($stmt->partitions);
}
$count = $stmt->partitionsNum ?? count($stmt->partitions);
$partitionDetails['partition_count'] = $count;
}
@ -871,11 +872,8 @@ class StructureController extends AbstractController
$openPos + 1,
$closePos - ($openPos + 1)
));
if (isset($stmt->subpartitionsNum)) {
$count = $stmt->subpartitionsNum;
} else {
$count = count($stmt->partitions[0]->subpartitions);
}
$count = $stmt->subpartitionsNum ?? count($stmt->partitions[0]->subpartitions);
$partitionDetails['subpartition_count'] = $count;
}
@ -1661,6 +1659,9 @@ class StructureController extends AbstractController
$max_digits,
$decimals
);
$avg_size = '';
$avg_unit = '';
if ($table_info_num_rows > 0) {
[$avg_size, $avg_unit] = Util::formatByteDown(
($showtable['Data_length']
@ -1669,8 +1670,6 @@ class StructureController extends AbstractController
6,
1
);
} else {
$avg_size = $avg_unit = '';
}
/** @var Innodb $innodbEnginePlugin */

View File

@ -570,9 +570,11 @@ class Core
// but we need it when coming from the cookie login panel)
if ($GLOBALS['config']->get('PMA_IS_IIS') && $use_refresh) {
$response->header('Refresh: 0; ' . $uri);
} else {
$response->header('Location: ' . $uri);
return;
}
$response->header('Location: ' . $uri);
}
/**
@ -780,12 +782,10 @@ class Core
$query = http_build_query(['url' => $vars['url']]);
if ($GLOBALS['config'] !== null && $GLOBALS['config']->get('is_setup')) {
$url = '../url.php?' . $query;
} else {
$url = './url.php?' . $query;
return '../url.php?' . $query;
}
return $url;
return './url.php?' . $query;
}
/**
@ -1408,13 +1408,15 @@ class Core
// Returning page.
$back = $_REQUEST['back'];
$container->setParameter('back', $back);
} else {
if ($config->issetCookie('back')) {
$config->removeCookie('back');
}
unset($_REQUEST['back'], $_GET['back'], $_POST['back']);
return;
}
if ($config->issetCookie('back')) {
$config->removeCookie('back');
}
unset($_REQUEST['back'], $_GET['back'], $_POST['back']);
}
public static function connectToDatabaseServer(DatabaseInterface $dbi, AuthenticationPlugin $auth): void

View File

@ -138,14 +138,15 @@ class CreateAddField
$sqlSuffix .= ' AFTER '
. Util::backquote($_POST['after_field']);
}
} else {
$sqlSuffix .= ' AFTER '
. Util::backquote(
$_POST['field_name'][$previousField]
);
return $sqlSuffix;
}
return $sqlSuffix;
return $sqlSuffix
. ' AFTER '
. Util::backquote(
$_POST['field_name'][$previousField]
);
}
/**

View File

@ -1128,14 +1128,17 @@ class DatabaseInterface implements DbalInterface
self::CONNECT_USER,
self::QUERY_STORE
);
if ($result === false) {
trigger_error(
__('Failed to set configured collation connection!'),
E_USER_WARNING
);
} else {
$GLOBALS['collation_connection'] = $collation;
return;
}
$GLOBALS['collation_connection'] = $collation;
}
/**

View File

@ -248,9 +248,11 @@ class Encoding
$parts = explode(',', self::$kanjiEncodings);
if ($parts[1] === 'EUC-JP') {
self::$kanjiEncodings = 'ASCII,SJIS,EUC-JP,JIS';
} else {
self::$kanjiEncodings = 'ASCII,EUC-JP,SJIS,JIS';
return;
}
self::$kanjiEncodings = 'ASCII,EUC-JP,SJIS,JIS';
}
/**
@ -279,12 +281,10 @@ class Encoding
}
if ($string_encoding != $enc && $enc != '') {
$dist = mb_convert_encoding($str, $enc, $string_encoding);
} else {
$dist = $str;
return mb_convert_encoding($str, $enc, $string_encoding);
}
return $dist;
return $str;
}
/**