Remove inline if clauses
This commit is contained in:
56
MD_STD.php
56
MD_STD.php
@ -44,7 +44,9 @@ final class MD_STD {
|
||||
public static function realpath(string $path):string {
|
||||
|
||||
$output = \realpath($path);
|
||||
if (!\is_string($output)) throw new MDFileDoesNotExist("The file {$path} does not exist or is not readable.");
|
||||
if (!\is_string($output)) {
|
||||
throw new MDFileDoesNotExist("The file {$path} does not exist or is not readable.");
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -124,7 +126,9 @@ final class MD_STD {
|
||||
public static function ob_get_clean():string {
|
||||
|
||||
$output = \ob_get_clean();
|
||||
if ($output === false) throw new MDOutputBufferNotStarted("Output buffer was not started");
|
||||
if ($output === false) {
|
||||
throw new MDOutputBufferNotStarted("Output buffer was not started");
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -139,8 +143,12 @@ final class MD_STD {
|
||||
*/
|
||||
public static function startsWith(string $haystack, string $needle):bool {
|
||||
|
||||
if (substr($haystack, 0, \strlen($needle)) == $needle) return true;
|
||||
else return false;
|
||||
if (substr($haystack, 0, \strlen($needle)) === $needle) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -157,7 +165,9 @@ final class MD_STD {
|
||||
$output = false;
|
||||
foreach ($needles as $needle) {
|
||||
$output = self::startsWith($haystack, $needle);
|
||||
if ($output == true) return $output;
|
||||
if ($output == true) {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
|
||||
@ -197,7 +207,9 @@ final class MD_STD {
|
||||
public static function json_encode(array $value, int $options = 0, int $depth = 512):string {
|
||||
|
||||
$output = \json_encode($value, $options, $depth);
|
||||
if ($output === false) throw new Exception("JSON output could not be generated");
|
||||
if ($output === false) {
|
||||
throw new Exception("JSON output could not be generated");
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -212,7 +224,9 @@ final class MD_STD {
|
||||
public static function strtotime(string $datetime):int {
|
||||
|
||||
$output = \strtotime($datetime);
|
||||
if ($output === false) throw new MDInvalidInputDate("Invalid input date {$datetime}.");
|
||||
if ($output === false) {
|
||||
throw new MDInvalidInputDate("Invalid input date {$datetime}.");
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -268,7 +282,9 @@ final class MD_STD {
|
||||
// if ($errmsg = curl_error($curl)) echo $errmsg;
|
||||
|
||||
\curl_close($curl);
|
||||
if (\is_bool($result)) return "";
|
||||
if (\is_bool($result)) {
|
||||
return "";
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
@ -333,7 +349,9 @@ final class MD_STD {
|
||||
|
||||
// $_SERVER['HTTP_ACCEPT_LANGUAGE'] verwenden, wenn keine Sprachvariable mitgegeben wurde
|
||||
if ($lang_variable === "") {
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
}
|
||||
}
|
||||
|
||||
// wurde irgendwelche Information mitgeschickt?
|
||||
@ -344,7 +362,9 @@ final class MD_STD {
|
||||
|
||||
// Den Header auftrennen
|
||||
$accepted_languages = preg_split('/,\s*/', $lang_variable);
|
||||
if (!is_array($accepted_languages)) return $default_language;
|
||||
if (!is_array($accepted_languages)) {
|
||||
return $default_language;
|
||||
}
|
||||
|
||||
// Die Standardwerte einstellen
|
||||
$current_lang = $default_language;
|
||||
@ -453,7 +473,9 @@ final class MD_STD {
|
||||
public static function openssl_random_pseudo_bytes(int $length):string {
|
||||
|
||||
$output = \openssl_random_pseudo_bytes($length);
|
||||
if ($output === false) throw new Exception("Failed generating random pseudo bytes using openssl_random_pseudo_bytes");
|
||||
if ($output === false) {
|
||||
throw new Exception("Failed generating random pseudo bytes using openssl_random_pseudo_bytes");
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -469,7 +491,9 @@ final class MD_STD {
|
||||
|
||||
$input = \explode(PHP_EOL, $input);
|
||||
$output = "";
|
||||
foreach ($input as $line) $output .= \trim($line) . PHP_EOL;
|
||||
foreach ($input as $line) {
|
||||
$output .= \trim($line) . PHP_EOL;
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
@ -572,8 +596,12 @@ final class MD_STD {
|
||||
*/
|
||||
public static function levenshtein(string $str1, string $str2):int {
|
||||
|
||||
if (\strlen($str1) > 250) $str1 = \substr($str1, 0, 250);
|
||||
if (\strlen($str2) > 250) $str2 = \substr($str2, 0, 250);
|
||||
if (\strlen($str1) > 250) {
|
||||
$str1 = \substr($str1, 0, 250);
|
||||
}
|
||||
if (\strlen($str2) > 250) {
|
||||
$str2 = \substr($str2, 0, 250);
|
||||
}
|
||||
|
||||
return \levenshtein($str1, $str2);
|
||||
|
||||
|
Reference in New Issue
Block a user