From 02d4a560a134403f444e5a0e955c26a796426763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Fri, 24 Jun 2022 23:34:04 +0200 Subject: [PATCH] Changes: - added type-hint + intval() (@MrPetovan) - also changed `if (!$foo == '')` to `if ($foo != '')` - added some spaces for better readability --- convert/convert.php | 19 +++++++++---------- impressum/impressum.php | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/convert/convert.php b/convert/convert.php index 9c72cbed..53e6d2d3 100644 --- a/convert/convert.php +++ b/convert/convert.php @@ -44,15 +44,15 @@ function convert_content(App $a) { private function findBaseUnit($from, $to) { while (list($skey, $sval) = each($this->bases)) { - if ($skey == $from || $to == $skey || in_array($to, $sval) || in_array($from, $sval)) { - return $skey; - } + if ($skey == $from || $to == $skey || in_array($to, $sval) || in_array($from, $sval)) { + return $skey; + } } return false; } - public function getTable($value, $from_unit, $to_unit, $precision): string + public function getTable(int $value, $from_unit, $to_unit, $precision): string { $string = ''; @@ -176,10 +176,10 @@ function convert_content(App $a) { ] ]; - while (list($key,$val) = each($conversions)) { + while (list($key, $val) = each($conversions)) { $conv->addConversion($val['base'], $val['conv']); $list[$key][] = $val['base']; - while (list($ukey,$uval) = each($val['conv'])) { + while (list($ukey, $uval) = each($val['conv'])) { $list[$key][] = $ukey; } } @@ -187,8 +187,7 @@ function convert_content(App $a) { $o .= '

Unit Conversions

'; if (isset($_POST['from_unit']) && isset($_POST['value'])) { - $_POST['value'] = $_POST['value'] + 0; - $o .= ($conv->getTable($_POST['value'], $_POST['from_unit'], $_POST['to_unit'], 5)) . '

'; + $o .= ($conv->getTable(intval($_POST['value']), $_POST['from_unit'], $_POST['to_unit'], 5)) . '

'; } else { $o .= '

Select:

'; } @@ -204,9 +203,9 @@ function convert_content(App $a) { $o .= '