fix indentation problem and simplify a function
cover fix indentation problem and simplify a function
Commit changes are self-explains.
Victor Huesca (2):
web/funcs.inc.php: fix 'bab_format_sql_filter' indentation web/index.php: reword the 'format_duration' function
web/funcs.inc.php | 42 +++++++++++++++++++++--------------------- web/index.php | 22 ++-------------------- 2 files changed, 23 insertions(+), 41 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/2 web/funcs.inc.php: fix 'bab_format_sql_filter' indentation
The 'bab_format_sql_filter' function uses tabs indentation whereas the overall file uses two spaces. This patch simply replace those tabs by spaces for consistency.
--- web/funcs.inc.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
web/funcs.inc.php +21 -21
@@ -32,29 +32,29 @@ function bab_footer() function bab_format_sql_filter($db, $filters) { - $status_map = array( - "OK" => 0, - "NOK" => 1, - "TIMEOUT" => 2, - ); + $status_map = array( + "OK" => 0, + "NOK" => 1, + "TIMEOUT" => 2, + ); - $sql_filters = implode(' and ', array_map( - function ($v, $k) use ($db, $status_map) { - if ($k == "reason") - return sprintf("%s like %s", $k, $db->quote_smart($v)); - else if ($k == "status") - return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v])); - else - return sprintf("%s=%s", $k, $db->quote_smart($v)); - }, - $filters, - array_keys($filters) - )); + $sql_filters = implode(' and ', array_map( + function ($v, $k) use ($db, $status_map) { + if ($k == "reason") + return sprintf("%s like %s", $k, $db->quote_smart($v)); + else if ($k == "status") + return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v])); + else + return sprintf("%s=%s", $k, $db->quote_smart($v)); + }, + $filters, + array_keys($filters) + )); - if (count($filters)) - return "where " . $sql_filters; - else - return ""; + if (count($filters)) + return "where " . $sql_filters; + else + return ""; } /*
Signature · 1 line
2.21.0
PATCH 2/2 web/index.php: reword the 'format_duration' function
In reply to Victor HuescaThe format_duration manually compute everything when it could just use the build-in date format function and trim the beginning for the same result.
--- web/index.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-)
web/index.php +2 -20
@@ -1,26 +1,8 @@ <?php include("funcs.inc.php"); -function format_duration($seconds_count) -{ - $delimiter = ':'; - $seconds = $seconds_count % 60; - $minutes = floor($seconds_count/60) % 60; - $hours = floor($seconds_count/3600); - - $seconds = str_pad($seconds, 2, "0", STR_PAD_LEFT); - $minutes = str_pad($minutes, 2, "0", STR_PAD_LEFT).$delimiter; - - if($hours > 0) - { - $hours = str_pad($hours, 2, "0", STR_PAD_LEFT).$delimiter; - } - else - { - $hours = ''; - } - - return "$hours$minutes$seconds"; +function format_duration($seconds_count) { + return ltrim(gmdate('H:i:s', $seconds_count), '0:'); } function format_url_args($args)
Signature · 1 line
2.21.0
cover fix indentation problem and simplify a function
In reply to Victor HuescaQuoted 3 lines · On Mon, 12 Aug 2019 16:43:43 +0200 Victor Huesca <[email protected]>…
Victor Huesca (2):
web/funcs.inc.php: fix 'bab_format_sql_filter' indentation web/index.php: reword the 'format_duration' function
Both applied to buildroot-test. Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com