Remove inline if clauses

This commit is contained in:
2021-02-06 20:08:37 +01:00
parent 217e1fc86b
commit 8aa9d94acf
4 changed files with 69 additions and 23 deletions

View File

@ -44,7 +44,9 @@ final class MD_STD_IN {
*/
public static function sanitize_id_or_zero($input):int {
if ($input === "") return 0;
if ($input === "") {
return 0;
}
$input = \filter_var($input, \FILTER_VALIDATE_INT, [
'options' => [
@ -76,7 +78,9 @@ final class MD_STD_IN {
FILTER_SANITIZE_STRING,
FILTER_FLAG_NO_ENCODE_QUOTES);
if ($output === false) return "";
if ($output === false) {
return "";
}
while (strpos($output, " ") !== false) {
$output = str_replace(" ", " ", $output);
}
@ -126,7 +130,9 @@ final class MD_STD_IN {
else if (isset($_POST[$var_name])) {
$output = self::sanitize_text($_POST[$var_name]);
}
else $output = self::sanitize_text($default);
else {
$output = self::sanitize_text($default);
}
if (!empty($allowed) and !\in_array($output, $allowed, true)) {
throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: '" . implode('\', \'', $allowed) . "'");
@ -151,7 +157,9 @@ final class MD_STD_IN {
if (isset($_POST[$var_name])) {
$output = self::sanitize_text($_POST[$var_name]);
}
else $output = self::sanitize_text($default);
else {
$output = self::sanitize_text($default);
}
if (!empty($allowed) and !\in_array($output, $allowed, true)) {
throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: '" . implode('\', \'', $allowed) . "'");
@ -170,7 +178,9 @@ final class MD_STD_IN {
*/
public static function sanitize_url($input):string {
if ($input === "") return "";
if ($input === "") {
return "";
}
$output = \filter_var($input, FILTER_SANITIZE_URL);
if (($output = \filter_var($output, FILTER_VALIDATE_URL)) === false) {
@ -190,7 +200,9 @@ final class MD_STD_IN {
*/
public static function sanitize_email($input):string {
if ($input === "") return "";
if ($input === "") {
return "";
}
$output = \filter_var($input, FILTER_SANITIZE_EMAIL);
if (($output = \filter_var($output, FILTER_VALIDATE_EMAIL)) === false) {
@ -227,7 +239,9 @@ final class MD_STD_IN {
*/
public static function validate_isbn(string $input):string {
if ($input === "") return "";
if ($input === "") {
return "";
}
// Remove hyphens
$input = trim(strtr($input, ["-" => "", "" => ""]));