From c981add07c6f01e4316474ea4c82a759324a16cf Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Thu, 11 Nov 2021 16:19:16 +0100 Subject: [PATCH] Smaller, Better, PHPstorm. Refactored some Variabled --- app/Http/Controllers/HomeController.php | 109 ++++++++++-------------- 1 file changed, 47 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index bbfa7f62..6c8e583d 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,4 +1,5 @@ = 15): - return $this::TIME_LEFT_BG_SUCCESS; - break; - - case ($days >= 8 && $days <= 14): - return $this::TIME_LEFT_BG_WARNING; - break; - - case ($days <= 7): - return $this::TIME_LEFT_BG_DANGER; - break; - - default: - return $this::TIME_LEFT_BG_WARNING; + if ($days >= 15) { + return $this::TIME_LEFT_BG_SUCCESS; } + if ($days <= 7) { + return $this::TIME_LEFT_BG_DANGER; + } + return $this::TIME_LEFT_BG_WARNING; } + /** - * @description Set "hours", "days" or nothing behind the remaining time - * - * @param float $days - * @param float $hours - * - * @return string - */ + * @description Set "hours", "days" or nothing behind the remaining time + * + * @param float $days + * @param float $hours + * + * @return string|void + */ public function getTimeLeftBoxUnit(float $days, float $hours) { - if ($days < 1) - { - if ($hours < 1) - { + if ($days < 1) { + if ($hours < 1) { return; - } - else - { + } else { return "hours"; } } @@ -73,23 +64,19 @@ class HomeController extends Controller } /** - * @description Get the Text for the Days-Left-Box in HomeView - * - * @param float $days - * @param float $hours - * - * @return string - */ + * @description Get the Text for the Days-Left-Box in HomeView + * + * @param float $days + * @param float $hours + * + * @return string + */ public function getTimeLeftBoxText(float $days, float $hours) { - if ($days < 1) - { - if ($hours < 1) - { + if ($days < 1) { + if ($hours < 1) { return $this::TIME_LEFT_OUT_OF_CREDITS_TEXT; - } - else - { + } else { return strval($hours); } } @@ -106,19 +93,17 @@ class HomeController extends Controller $unit = ""; /** Build our Time-Left-Box */ - if ($credits > 0.01 and $usage > 0) - { - $days = number_format(($credits * 30) / $usage, 2, '.', ''); - $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', ''); + if ($credits > 0.01 and $usage > 0) { + $daysLeft = number_format(($credits * 30) / $usage, 2, '.', ''); + $hoursLeft = number_format($credits / ($usage / 30 / 24), 2, '.', ''); - $bg = $this->getTimeLeftBoxBackground($days); - $boxText = $this->getTimeLeftBoxText($days, $hours); - $unit = $this->getTimeLeftBoxUnit($days, $hours); + $bg = $this->getTimeLeftBoxBackground($daysLeft); + $boxText = $this->getTimeLeftBoxText($daysLeft, $hoursLeft); + $unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : "hours") : "daysLeft"; } - // RETURN ALL VALUES return view('home')->with([ 'useage' => $usage,