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 01:30:25 +02:00
parent db01d6a9da
commit d005ea8041
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
8 changed files with 79 additions and 71 deletions

View File

@ -348,14 +348,12 @@ class ServerConfigChecks
* @param bool $cookieAuthUsed Cookie auth is used
* @param bool $blowfishSecretSet Blowfish secret set
* @param string $blowfishSecret Blowfish secret
*
* @return void
*/
protected function performConfigChecksCookieAuthUsed(
$cookieAuthUsed,
$blowfishSecretSet,
$blowfishSecret
) {
): void {
// $cfg['blowfish_secret']
// it's required for 'cookie' authentication
if (! $cookieAuthUsed) {
@ -375,38 +373,42 @@ class ServerConfigChecks
. 'remember it.'
))
);
} else {
$blowfishWarnings = [];
// check length
if (strlen($blowfishSecret) < 32) {
// too short key
$blowfishWarnings[] = __(
'Key is too short, it should have at least 32 characters.'
);
}
// check used characters
$hasDigits = (bool) preg_match('/\d/', $blowfishSecret);
$hasChars = (bool) preg_match('/\S/', $blowfishSecret);
$hasNonword = (bool) preg_match('/\W/', $blowfishSecret);
if (! $hasDigits || ! $hasChars || ! $hasNonword) {
$blowfishWarnings[] = Sanitize::sanitizeMessage(
__(
'Key should contain letters, numbers [em]and[/em] '
. 'special characters.'
)
);
}
if (! empty($blowfishWarnings)) {
SetupIndex::messagesSet(
'error',
'blowfish_warnings' . count($blowfishWarnings),
Descriptions::get('blowfish_secret'),
implode('<br>', $blowfishWarnings)
);
}
return;
}
$blowfishWarnings = [];
// check length
if (strlen($blowfishSecret) < 32) {
// too short key
$blowfishWarnings[] = __(
'Key is too short, it should have at least 32 characters.'
);
}
// check used characters
$hasDigits = (bool) preg_match('/\d/', $blowfishSecret);
$hasChars = (bool) preg_match('/\S/', $blowfishSecret);
$hasNonword = (bool) preg_match('/\W/', $blowfishSecret);
if (! $hasDigits || ! $hasChars || ! $hasNonword) {
$blowfishWarnings[] = Sanitize::sanitizeMessage(
__(
'Key should contain letters, numbers [em]and[/em] '
. 'special characters.'
)
);
}
if (empty($blowfishWarnings)) {
return;
}
SetupIndex::messagesSet(
'error',
'blowfish_warnings' . count($blowfishWarnings),
Descriptions::get('blowfish_secret'),
implode('<br>', $blowfishWarnings)
);
}
/**

View File

@ -26,15 +26,17 @@ class LicenseController extends AbstractController
// Check if the file is available, some distributions remove these.
if (@is_readable($filename)) {
readfile($filename);
} else {
printf(
__(
'The %s file is not available on this system, please visit ' .
'%s for more information.'
),
$filename,
'https://www.phpmyadmin.net/'
);
return;
}
printf(
__(
'The %s file is not available on this system, please visit ' .
'%s for more information.'
),
$filename,
'https://www.phpmyadmin.net/'
);
}
}

View File

@ -115,8 +115,10 @@ class NavigationController extends AbstractController
if ($this->response->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
return;
}
define('PMA_DISABLE_NAVI_SETTINGS', true);
}
}

View File

@ -70,10 +70,10 @@ class UploadProgress implements UploadInterface
}
if ($status) {
$ret['finished'] = false;
if ($status['bytes_uploaded'] == $status['bytes_total']) {
$ret['finished'] = true;
} else {
$ret['finished'] = false;
}
$ret['total'] = $status['bytes_total'];

View File

@ -73,12 +73,12 @@ abstract class ImportPlugin
*/
protected function getDbnameAndOptions($currentDb, $defaultDb)
{
$db_name = $defaultDb;
$options = null;
if (strlen((string) $currentDb) > 0) {
$db_name = $currentDb;
$options = ['create_db' => false];
} else {
$db_name = $defaultDb;
$options = null;
}
return [

View File

@ -78,10 +78,10 @@ class Dia extends XMLWriter
$rightMargin,
$orientation
) {
$isPortrait = 'false';
if ($orientation === 'P') {
$isPortrait = 'true';
} else {
$isPortrait = 'false';
}
$this->startElement('dia:diagram');

View File

@ -34,11 +34,13 @@ class WindowsNt extends Base
{
if (! class_exists('COM')) {
$this->wmi = null;
} else {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$this->wmi = $objLocator->ConnectServer();
return;
}
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$this->wmi = $objLocator->ConnectServer();
}
/**

View File

@ -99,18 +99,18 @@ class ConfigGenerator
. var_export($var_value, true) . ';' . $crlf;
}
$ret = '';
if (self::isZeroBasedArray($var_value)) {
$ret = "\$cfg['" . $var_name . "'] = "
return "\$cfg['" . $var_name . "'] = "
. self::exportZeroBasedArray($var_value, $crlf)
. ';' . $crlf;
} else {
// string keys: $cfg[key][subkey] = value
foreach ($var_value as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= "\$cfg['" . $var_name . "']['" . $k . "'] = "
. var_export($v, true) . ';' . $crlf;
}
}
$ret = '';
// string keys: $cfg[key][subkey] = value
foreach ($var_value as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= "\$cfg['" . $var_name . "']['" . $k . "'] = "
. var_export($v, true) . ';' . $crlf;
}
return $ret;
@ -152,13 +152,13 @@ class ConfigGenerator
$ret = 'array(';
if (count($retv) <= 4) {
// up to 4 values - one line
$ret .= implode(', ', $retv);
} else {
// more than 4 values - value per line
$imax = count($retv);
for ($i = 0; $i < $imax; $i++) {
$ret .= ($i > 0 ? ',' : '') . $crlf . ' ' . $retv[$i];
}
return $ret . implode(', ', $retv) . ')';
}
// more than 4 values - value per line
$imax = count($retv);
for ($i = 0; $i < $imax; $i++) {
$ret .= ($i > 0 ? ',' : '') . $crlf . ' ' . $retv[$i];
}
return $ret . ')';