diff options
author | William Desportes <williamdes@wdes.fr> | 2021-04-29 02:30:25 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2021-04-29 02:30:25 +0300 |
commit | d005ea8041f18e1ea660ba3005dcfde9bc98068c (patch) | |
tree | 3662ad43924cb7e988a6d1836122a030a0340be5 /libraries/classes/Config | |
parent | db01d6a9dab03c80d77d1f66e2ccf94464ba6530 (diff) |
Remove some else conditions by using early exits or moving code
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'libraries/classes/Config')
-rw-r--r-- | libraries/classes/Config/ServerConfigChecks.php | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/libraries/classes/Config/ServerConfigChecks.php b/libraries/classes/Config/ServerConfigChecks.php index 1adf128e3b..9c93792e48 100644 --- a/libraries/classes/Config/ServerConfigChecks.php +++ b/libraries/classes/Config/ServerConfigChecks.php @@ -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.' - ) - ); - } + return; + } - if (! empty($blowfishWarnings)) { - SetupIndex::messagesSet( - 'error', - 'blowfish_warnings' . count($blowfishWarnings), - Descriptions::get('blowfish_secret'), - implode('<br>', $blowfishWarnings) - ); - } + $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) + ); } /** |