Remove useless elses

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2020-05-26 22:27:45 -03:00
parent 2d02a15de3
commit 82c2964bb8
40 changed files with 262 additions and 266 deletions

View File

@ -142,32 +142,32 @@ if (isset($_POST['start'])) {
header('Location: ' . $url);
exit;
} else {
/* Grab query string */
if (! count($_POST)) {
[, $queryString] = explode('?', $_SERVER['REQUEST_URI']);
} else {
// I hate php sometimes
$queryString = file_get_contents('php://input');
}
/* Check reply */
try {
$message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
} catch (Throwable $e) {
Die_error($e);
}
$id = $message->get('openid.claimed_id');
if (! empty($id) && isset($AUTH_MAP[$id])) {
$_SESSION['PMA_single_signon_user'] = $AUTH_MAP[$id]['user'];
$_SESSION['PMA_single_signon_password'] = $AUTH_MAP[$id]['password'];
session_write_close();
/* Redirect to phpMyAdmin (should use absolute URL here!) */
header('Location: ../index.php');
} else {
Show_page('<p>User not allowed!</p>');
exit;
}
}
/* Grab query string */
if (! count($_POST)) {
[, $queryString] = explode('?', $_SERVER['REQUEST_URI']);
} else {
// I hate php sometimes
$queryString = file_get_contents('php://input');
}
/* Check reply */
try {
$message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
} catch (Throwable $e) {
Die_error($e);
}
$id = $message->get('openid.claimed_id');
if (! empty($id) && isset($AUTH_MAP[$id])) {
$_SESSION['PMA_single_signon_user'] = $AUTH_MAP[$id]['user'];
$_SESSION['PMA_single_signon_password'] = $AUTH_MAP[$id]['password'];
session_write_close();
/* Redirect to phpMyAdmin (should use absolute URL here!) */
header('Location: ../index.php');
} else {
Show_page('<p>User not allowed!</p>');
exit;
}

View File

@ -261,53 +261,53 @@ class CheckUserPrivileges
// @todo we should not break here, cause GRANT ALL *.*
// could be revoked by a later rule like GRANT SELECT ON db.*
break;
} else {
// this array may contain wildcards
$GLOBALS['dbs_where_create_table_allowed'][] = $show_grants_dbname;
}
$dbname_to_test = Util::backquote($show_grants_dbname);
// this array may contain wildcards
$GLOBALS['dbs_where_create_table_allowed'][] = $show_grants_dbname;
if ($GLOBALS['is_create_db_priv']) {
// no need for any more tests if we already know this
continue;
}
$dbname_to_test = Util::backquote($show_grants_dbname);
// does this db exist?
if ((preg_match('/' . $re0 . '%|_/', $show_grants_dbname)
&& ! preg_match('/\\\\%|\\\\_/', $show_grants_dbname))
|| (! $this->dbi->tryQuery(
'USE ' . preg_replace(
'/' . $re1 . '(%|_)/',
'\\1\\3',
$dbname_to_test
)
)
&& mb_substr($this->dbi->getError(), 1, 4) != 1044)
) {
/**
* Do not handle the underscore wildcard
* (this case must be rare anyway)
*/
$GLOBALS['db_to_create'] = preg_replace(
'/' . $re0 . '%/',
'\\1',
$show_grants_dbname
);
$GLOBALS['db_to_create'] = preg_replace(
if ($GLOBALS['is_create_db_priv']) {
// no need for any more tests if we already know this
continue;
}
// does this db exist?
if ((preg_match('/' . $re0 . '%|_/', $show_grants_dbname)
&& ! preg_match('/\\\\%|\\\\_/', $show_grants_dbname))
|| (! $this->dbi->tryQuery(
'USE ' . preg_replace(
'/' . $re1 . '(%|_)/',
'\\1\\3',
$GLOBALS['db_to_create']
);
$GLOBALS['is_create_db_priv'] = true;
$dbname_to_test
)
)
&& mb_substr($this->dbi->getError(), 1, 4) != 1044)
) {
/**
* Do not handle the underscore wildcard
* (this case must be rare anyway)
*/
$GLOBALS['db_to_create'] = preg_replace(
'/' . $re0 . '%/',
'\\1',
$show_grants_dbname
);
$GLOBALS['db_to_create'] = preg_replace(
'/' . $re1 . '(%|_)/',
'\\1\\3',
$GLOBALS['db_to_create']
);
$GLOBALS['is_create_db_priv'] = true;
/**
* @todo collect $GLOBALS['db_to_create'] into an array,
* to display a drop-down in the "Create database" dialog
*/
// we don't break, we want all possible databases
//break;
} // end if
} // end elseif
/**
* @todo collect $GLOBALS['db_to_create'] into an array,
* to display a drop-down in the "Create database" dialog
*/
// we don't break, we want all possible databases
//break;
} // end if // end elseif
} // end if
} // end while

View File

@ -57,24 +57,24 @@ final class CacheWarmupCommand extends Command
return $this->warmUpTwigCache($output);
} elseif ($input->getOption('routing') === true) {
return $this->warmUpRoutingCache($output);
} else {
$output->writeln('Warming up all caches.', OutputInterface::VERBOSITY_VERBOSE);
$twigCode = $this->warmUptwigCache($output);
if ($twigCode !== 0) {
$output->writeln('Twig cache generation had an error.');
return $twigCode;
}
$routingCode = $this->warmUpTwigCache($output);
if ($routingCode !== 0) {
$output->writeln('Routing cache generation had an error.');
return $twigCode;
}
$output->writeln('Warm up of all caches done.', OutputInterface::VERBOSITY_VERBOSE);
return 0;
}
$output->writeln('Warming up all caches.', OutputInterface::VERBOSITY_VERBOSE);
$twigCode = $this->warmUptwigCache($output);
if ($twigCode !== 0) {
$output->writeln('Twig cache generation had an error.');
return $twigCode;
}
$routingCode = $this->warmUpTwigCache($output);
if ($routingCode !== 0) {
$output->writeln('Routing cache generation had an error.');
return $twigCode;
}
$output->writeln('Warm up of all caches done.', OutputInterface::VERBOSITY_VERBOSE);
return 0;
}
private function warmUpRoutingCache(OutputInterface $output): int

View File

@ -1125,9 +1125,9 @@ class Config
{
if (isset($_COOKIE[$this->getCookieName($cookieName)])) {
return $_COOKIE[$this->getCookieName($cookieName)];
} else {
return null;
}
return null;
}
/**

View File

@ -109,9 +109,9 @@ class PageSettings
$response->getFooter()->getSelfUrl()
);
exit;
} else {
$error = $result;
}
$error = $result;
}
}

View File

@ -598,6 +598,7 @@ final class ImportController extends AbstractController
Util::handleDisableFKCheckCleanup($default_fk_check);
} catch (Throwable $e) {
Util::handleDisableFKCheckCleanup($default_fk_check);
throw $e;
}
}

View File

@ -83,9 +83,9 @@ class ExportController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -83,9 +83,9 @@ class FeaturesController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -83,9 +83,9 @@ class ImportController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -83,9 +83,9 @@ class MainPanelController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -83,9 +83,9 @@ class NavigationController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -83,9 +83,9 @@ class SqlController extends AbstractController
);
return;
} else {
$error = $result;
}
$error = $result;
}
// display forms

View File

@ -51,10 +51,10 @@ class TwoFactorController extends AbstractController
]);
return;
} else {
$twoFactor->configure('');
Message::rawNotice(__('Two-factor authentication has been removed.'))->display();
}
$twoFactor->configure('');
Message::rawNotice(__('Two-factor authentication has been removed.'))->display();
} elseif (isset($_POST['2fa_configure'])) {
if (! $twoFactor->configure($_POST['2fa_configure'])) {
echo $this->template->render('preferences/two_factor/configure', [
@ -63,9 +63,9 @@ class TwoFactorController extends AbstractController
]);
return;
} else {
Message::rawNotice(__('Two-factor authentication has been configured.'))->display();
}
Message::rawNotice(__('Two-factor authentication has been configured.'))->display();
}
$backend = $twoFactor->getBackend();

View File

@ -471,9 +471,9 @@ class PrivilegesController extends AbstractController
$this->response->addJSON('title', $title);
return;
} else {
$this->response->addHTML('<h2>' . $title . '</h2>' . $export);
}
$this->response->addHTML('<h2>' . $title . '</h2>' . $export);
}
if (isset($_GET['adduser'])) {

View File

@ -571,9 +571,9 @@ class Events
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
exit;
} else {
$message->display();
}
$message->display();
}
}

View File

@ -214,9 +214,9 @@ class Routines
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
exit;
} else {
$message->display();
}
$message->display();
}
}
}
@ -1447,11 +1447,11 @@ class Routines
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
exit;
} else {
echo $message->getDisplay();
unset($_POST);
//NOTE: Missing exit ?
}
echo $message->getDisplay();
unset($_POST);
//NOTE: Missing exit ?
}
$queries = is_array($routine) ? $this->getQueriesFromRoutineForm($routine) : [];
@ -1562,16 +1562,16 @@ class Routines
$this->response->addJSON('message', $message->getDisplay() . $output);
$this->response->addJSON('dialog', false);
exit;
} else {
echo $message->getDisplay() , $output;
if ($message->isError()) {
// At least one query has failed, so shouldn't
// execute any more queries, so we quit.
exit;
}
unset($_POST);
// Now deliberately fall through to displaying the routines list
}
echo $message->getDisplay() , $output;
if ($message->isError()) {
// At least one query has failed, so shouldn't
// execute any more queries, so we quit.
exit;
}
unset($_POST);
// Now deliberately fall through to displaying the routines list
}
/**

View File

@ -320,19 +320,19 @@ class Triggers
}
if (empty($temp)) {
return null;
} else {
$retval = [];
$retval['create'] = $temp['create'];
$retval['drop'] = $temp['drop'];
$retval['item_name'] = $temp['name'];
$retval['item_table'] = $temp['table'];
$retval['item_action_timing'] = $temp['action_timing'];
$retval['item_event_manipulation'] = $temp['event_manipulation'];
$retval['item_definition'] = $temp['definition'];
$retval['item_definer'] = $temp['definer'];
return $retval;
}
$retval = [];
$retval['create'] = $temp['create'];
$retval['drop'] = $temp['drop'];
$retval['item_name'] = $temp['name'];
$retval['item_table'] = $temp['table'];
$retval['item_action_timing'] = $temp['action_timing'];
$retval['item_event_manipulation'] = $temp['event_manipulation'];
$retval['item_definition'] = $temp['definition'];
$retval['item_definer'] = $temp['definer'];
return $retval;
}
/**
@ -580,9 +580,9 @@ class Triggers
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
exit;
} else {
$message->display();
}
$message->display();
}
}

View File

@ -124,9 +124,9 @@ class Encoding
self::$_engine = self::$_enginemap[$engine][1];
return;
} else {
Core::warnMissingExtension(self::$_enginemap[$engine][2]);
}
Core::warnMissingExtension(self::$_enginemap[$engine][2]);
}
/* Autodetection */

View File

@ -248,9 +248,9 @@ class File
{
if ($this->getName() === null) {
return false;
} else {
return is_uploaded_file($this->getName());
}
return is_uploaded_file($this->getName());
}
/**

View File

@ -449,42 +449,42 @@ class Git
}
return [trim($hash), $branch];
} else {
// deal with packed refs
$packedRefs = @file_get_contents($gitFolder . '/packed-refs');
if ($packedRefs === false) {
$this->config->set('PMA_VERSION_GIT', 0);
return [null, null];
}
// split file to lines
$refLines = explode(PHP_EOL, $packedRefs);
foreach ($refLines as $line) {
// skip comments
if ($line[0] == '#') {
continue;
}
// parse line
$parts = explode(' ', $line);
// care only about named refs
if (count($parts) != 2) {
continue;
}
// have found our ref?
if ($parts[1] == $refHead) {
$hash = $parts[0];
break;
}
}
if (! isset($hash)) {
$this->config->set('PMA_VERSION_GIT', 0);
// Could not find ref
return [null, null];
}
return [$hash, $branch];
}
// deal with packed refs
$packedRefs = @file_get_contents($gitFolder . '/packed-refs');
if ($packedRefs === false) {
$this->config->set('PMA_VERSION_GIT', 0);
return [null, null];
}
// split file to lines
$refLines = explode(PHP_EOL, $packedRefs);
foreach ($refLines as $line) {
// skip comments
if ($line[0] == '#') {
continue;
}
// parse line
$parts = explode(' ', $line);
// care only about named refs
if (count($parts) != 2) {
continue;
}
// have found our ref?
if ($parts[1] == $refHead) {
$hash = $parts[0];
break;
}
}
if (! isset($hash)) {
$this->config->set('PMA_VERSION_GIT', 0);
// Could not find ref
return [null, null];
}
return [$hash, $branch];
} else {
return [trim($refHead), $branch];
}

View File

@ -416,13 +416,13 @@ class Import
$GLOBALS['finished'] = true;
return $GLOBALS['import_text'];
} else {
$r = mb_substr($GLOBALS['import_text'], 0, $size);
$GLOBALS['offset'] += $size;
$GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size);
return $r;
}
$r = mb_substr($GLOBALS['import_text'], 0, $size);
$GLOBALS['offset'] += $size;
$GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size);
return $r;
}
$result = $import_handle->read($size);
@ -1675,10 +1675,10 @@ class Import
$message = Message::rawError($error);
$response->addJSON('message', $message);
exit;
} else {
// If everything fine, START a transaction.
$GLOBALS['dbi']->query('START TRANSACTION');
}
// If everything fine, START a transaction.
$GLOBALS['dbi']->query('START TRANSACTION');
}
/**

View File

@ -38,9 +38,9 @@ class AuthenticationConfig extends AuthenticationPlugin
$response->addJSON('reload_flag', '1');
if (defined('TESTSUITE')) {
return true;
} else {
exit;
}
exit;
}
return true;

View File

@ -105,9 +105,9 @@ class AuthenticationCookie extends AuthenticationPlugin
if (! $session_expired && $response->loginPage()) {
if (defined('TESTSUITE')) {
return true;
} else {
exit;
}
exit;
}
/**
@ -240,9 +240,9 @@ class AuthenticationCookie extends AuthenticationPlugin
if (! defined('TESTSUITE')) {
exit;
} else {
return true;
}
return true;
}
/**
@ -405,9 +405,9 @@ class AuthenticationCookie extends AuthenticationPlugin
$this->showFailure('no-activity');
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
return false;
}
// check password cookie
@ -522,9 +522,9 @@ class AuthenticationCookie extends AuthenticationPlugin
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
return false;
}
// Set server cookies if required (once per session) and, in this case,
// force reload to ensure the client accepts cookies
@ -544,9 +544,9 @@ class AuthenticationCookie extends AuthenticationPlugin
);
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
return false;
} // end if
return true;

View File

@ -41,9 +41,9 @@ class AuthenticationHttp extends AuthenticationPlugin
$response->addJSON('reload_flag', '1');
if (defined('TESTSUITE')) {
return true;
} else {
exit;
}
exit;
}
return $this->authForm();
@ -97,9 +97,9 @@ class AuthenticationHttp extends AuthenticationPlugin
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
return false;
}
/**

View File

@ -44,9 +44,9 @@ class AuthenticationSignon extends AuthenticationPlugin
if (! defined('TESTSUITE')) {
exit;
} else {
return false;
}
return false;
}
/**

View File

@ -345,9 +345,9 @@ abstract class AuthenticationPlugin
if ($response->loginPage()) {
if (defined('TESTSUITE')) {
return;
} else {
exit;
}
exit;
}
echo $this->template->render('login/header', ['theme' => $GLOBALS['PMA_Theme']]);
Message::rawNotice(

View File

@ -50,9 +50,9 @@ abstract class HexTransformationsPlugin extends TransformationsPlugin
if ($options[0] < 1) {
return bin2hex($buffer);
} else {
return chunk_split(bin2hex($buffer), $options[0], ' ');
}
return chunk_split(bin2hex($buffer), $options[0], ' ');
}
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */

View File

@ -45,7 +45,7 @@ abstract class InlineTransformationsPlugin extends TransformationsPlugin
$cfg = $GLOBALS['cfg'];
$options = $this->getOptions($options, $cfg['DefaultTransformations']['Inline']);
if (PMA_IS_GD2) {
if (defined('PMA_IS_GD2') && PMA_IS_GD2 === 1) {
return '<a href="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params'])
. '" rel="noopener noreferrer" target="_blank"><img src="'
. Url::getFromRoute('/transformation/wrapper', array_merge($options['wrapper_params'], [
@ -54,10 +54,10 @@ abstract class InlineTransformationsPlugin extends TransformationsPlugin
'newHeight' => (int) $options[1],
]))
. '" alt="[' . htmlspecialchars($buffer) . ']" border="0"></a>';
} else {
return '<img src="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params'])
. '" alt="[' . htmlspecialchars($buffer) . ']" width="320" height="240">';
}
return '<img src="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params'])
. '" alt="[' . htmlspecialchars($buffer) . ']" width="320" height="240">';
}
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */

View File

@ -165,8 +165,8 @@ class TwoFactorPlugin
if ($return_url) {
return $parsed['scheme'] . '://' . $parsed['host']
. (! empty($parsed['port']) ? ':' . $parsed['port'] : '');
} else {
return $parsed['host'];
}
return $parsed['host'];
}
}

View File

@ -28,9 +28,9 @@ class Replication
$list = explode('.', $string);
if ($what == 'db') {
return $list[0];
} else {
return $list[1];
}
return $list[1];
}
/**

View File

@ -97,9 +97,9 @@ class Privileges
if ($response->isAjax()) {
$response->addJSON('message', $dialog);
exit;
} else {
$html .= $dialog;
}
$html .= $dialog;
}
return $html;

View File

@ -405,10 +405,10 @@ class Monitor
// Group this value, thus do not add to the result list
continue 2;
} else {
$insertTablesFirst = $i;
$insertTables[$matches[2]] += $row['#'] - 1;
}
$insertTablesFirst = $i;
$insertTables[$matches[2]] += $row['#'] - 1;
}
// No break here

View File

@ -217,9 +217,9 @@ class Table
}
return false;
} else {
return $tbl_storage_engine == $engine;
}
return $tbl_storage_engine == $engine;
}
/**
@ -1803,10 +1803,10 @@ class Table
$move_columns_sql_result = $this->_dbi->tryQuery($move_columns_sql_query);
if ($move_columns_sql_result !== false) {
return $this->_dbi->getFieldsMeta($move_columns_sql_result);
} else {
// unsure how to reproduce but it was seen on the reporting server
return [];
}
// unsure how to reproduce but it was seen on the reporting server
return [];
}
/**

View File

@ -618,28 +618,28 @@ class Types
'ST_PolyFromWKB',
'ST_MPolyFromWKB',
];
} else {
return [
'GeomFromText',
'GeomFromWKB',
'GeomCollFromText',
'LineFromText',
'MLineFromText',
'PointFromText',
'MPointFromText',
'PolyFromText',
'MPolyFromText',
'GeomCollFromWKB',
'LineFromWKB',
'MLineFromWKB',
'PointFromWKB',
'MPointFromWKB',
'PolyFromWKB',
'MPolyFromWKB',
];
}
return [
'GeomFromText',
'GeomFromWKB',
'GeomCollFromText',
'LineFromText',
'MLineFromText',
'PointFromText',
'MPointFromText',
'PolyFromText',
'MPolyFromText',
'GeomCollFromWKB',
'LineFromWKB',
'MLineFromWKB',
'PointFromWKB',
'MPointFromWKB',
'PolyFromWKB',
'MPolyFromWKB',
];
}
return [];

View File

@ -3185,11 +3185,6 @@ parameters:
count: 1
path: libraries/classes/Plugins/Transformations/Abs/ExternalTransformationsPlugin.php
-
message: "#^If condition is always true\\.$#"
count: 1
path: libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Transformations\\\\Output\\\\Text_Plain_Binarytoip\\:\\:applyTransformation\\(\\) should return string but returns string\\|false\\.$#"
count: 1

View File

@ -44,8 +44,8 @@ if (Core::ifSetOr($_POST['submit_clear'], '')) {
$response->disable();
echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']);
exit;
} else {
// Show generated config file in a <textarea>
$response->generateHeader303('index.php' . Url::getCommonRaw(['page' => 'config']));
exit;
}
// Show generated config file in a <textarea>
$response->generateHeader303('index.php' . Url::getCommonRaw(['page' => 'config']));
exit;

View File

@ -164,9 +164,9 @@ class SearchControllerTest extends AbstractTestCase
'col1' => 1,
'col2' => 2,
];
} else {
return null;
}
return null;
}
)
);

View File

@ -128,9 +128,9 @@ class StructureControllerTest extends AbstractTestCase
'Key_name' => 'PRIMARY',
'Column_name' => 'column',
];
} else {
return null;
}
return null;
}
)
);

View File

@ -469,9 +469,9 @@ class DbiDummy implements DbiExtension
{
if ($result >= self::OFFSET_GLOBAL) {
return $GLOBALS['dummy_queries'][$result - self::OFFSET_GLOBAL];
} else {
return $this->_queries[$result];
}
return $this->_queries[$result];
}
private function init(): void

View File

@ -221,9 +221,9 @@ abstract class TestBase extends TestCase
return 'http://'
. getenv('TESTSUITE_SELENIUM_HOST') . ':'
. getenv('TESTSUITE_SELENIUM_PORT') . '/wd/hub';
} else {
return null;
}
return null;
}
/**