From 14bceeb31130e06e0aa3fbb7a371372641e21a10 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Mon, 8 Nov 2021 07:38:29 +0100 Subject: [PATCH 1/7] Fix "You Ran out of Credits - hours" --- app/Http/Controllers/HomeController.php | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3703b2f8..bbfa7f62 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -48,6 +48,30 @@ class HomeController extends Controller } } + /** + * @description Set "hours", "days" or nothing behind the remaining time + * + * @param float $days + * @param float $hours + * + * @return string + */ + public function getTimeLeftBoxUnit(float $days, float $hours) + { + if ($days < 1) + { + if ($hours < 1) + { + return; + } + else + { + return "hours"; + } + } + return "days"; + } + /** * @description Get the Text for the Days-Left-Box in HomeView * @@ -89,7 +113,7 @@ class HomeController extends Controller $bg = $this->getTimeLeftBoxBackground($days); $boxText = $this->getTimeLeftBoxText($days, $hours); - $unit = $days < 1 ? 'hours' : 'days'; + $unit = $this->getTimeLeftBoxUnit($days, $hours); } From c981add07c6f01e4316474ea4c82a759324a16cf Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Thu, 11 Nov 2021 16:19:16 +0100 Subject: [PATCH 2/7] 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, From e9017c908772fe770202668445d3cdb67ebf7d42 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Thu, 11 Nov 2021 16:25:29 +0100 Subject: [PATCH 3/7] Days -> DaysLeft --- app/Http/Controllers/HomeController.php | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 6c8e583d..b7f13db2 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -27,16 +27,16 @@ class HomeController extends Controller /** * @description Get the Background Color for the Days-Left-Box in HomeView * - * @param float $days + * @param float $daysLeft * * @return string */ - public function getTimeLeftBoxBackground(float $days): string + public function getTimeLeftBoxBackground(float $daysLeft): string { - if ($days >= 15) { + if ($daysLeft >= 15) { return $this::TIME_LEFT_BG_SUCCESS; } - if ($days <= 7) { + if ($daysLeft <= 7) { return $this::TIME_LEFT_BG_DANGER; } return $this::TIME_LEFT_BG_WARNING; @@ -46,15 +46,15 @@ class HomeController extends Controller /** * @description Set "hours", "days" or nothing behind the remaining time * - * @param float $days - * @param float $hours + * @param float $daysLeft + * @param float $hoursLeft * * @return string|void */ - public function getTimeLeftBoxUnit(float $days, float $hours) + public function getTimeLeftBoxUnit(float $daysLeft, float $hoursLeft) { - if ($days < 1) { - if ($hours < 1) { + if ($daysLeft < 1) { + if ($hoursLeft < 1) { return; } else { return "hours"; @@ -66,21 +66,21 @@ class HomeController extends Controller /** * @description Get the Text for the Days-Left-Box in HomeView * - * @param float $days - * @param float $hours + * @param float $daysLeft + * @param float $hoursLeft * * @return string */ - public function getTimeLeftBoxText(float $days, float $hours) + public function getTimeLeftBoxText(float $daysLeft, float $hoursLeft) { - if ($days < 1) { - if ($hours < 1) { + if ($daysLeft < 1) { + if ($hoursLeft < 1) { return $this::TIME_LEFT_OUT_OF_CREDITS_TEXT; } else { - return strval($hours); + return strval($hoursLeft); } } - return strval(number_format($days, 0)); + return strval(number_format($daysLeft, 0)); } /** Show the application dashboard. */ @@ -99,7 +99,7 @@ class HomeController extends Controller $bg = $this->getTimeLeftBoxBackground($daysLeft); $boxText = $this->getTimeLeftBoxText($daysLeft, $hoursLeft); - $unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : "hours") : "daysLeft"; + $unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : "hours") : "days"; } From 8b1445ae0dce9e62b241c31e2532ba9b6ccb2e7a Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 11 Nov 2021 17:16:25 +0100 Subject: [PATCH 4/7] Removed unnessecary comment --- app/Http/Controllers/HomeController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index b7f13db2..77c9af69 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -9,9 +9,7 @@ use App\Models\Configuration; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -/** - * - */ + class HomeController extends Controller { const TIME_LEFT_BG_SUCCESS = "bg-success"; From 021df3af4fa54bd51a1a659db53052312ab50801 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Fri, 12 Nov 2021 19:47:13 +0100 Subject: [PATCH 5/7] Shortening - Magic --- app/Http/Controllers/HomeController.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 77c9af69..abe0b608 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -51,14 +51,8 @@ class HomeController extends Controller */ public function getTimeLeftBoxUnit(float $daysLeft, float $hoursLeft) { - if ($daysLeft < 1) { - if ($hoursLeft < 1) { - return; - } else { - return "hours"; - } - } - return "days"; + if ($daysLeft > 1) return 'days'; + return $hoursLeft < 1 ? null : "hours"; } /** @@ -71,14 +65,9 @@ class HomeController extends Controller */ public function getTimeLeftBoxText(float $daysLeft, float $hoursLeft) { - if ($daysLeft < 1) { - if ($hoursLeft < 1) { - return $this::TIME_LEFT_OUT_OF_CREDITS_TEXT; - } else { - return strval($hoursLeft); - } - } - return strval(number_format($daysLeft, 0)); + if ($daysLeft > 1) return strval(number_format($daysLeft, 0)); + return ($hoursLeft < 1 ? $this::TIME_LEFT_OUT_OF_CREDITS_TEXT : strval($hoursLeft)); + } /** Show the application dashboard. */ From 93ce540b3f2e5b48427163cd7ebe77bd5969ec46 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Fri, 12 Nov 2021 19:48:28 +0100 Subject: [PATCH 6/7] remove space --- app/Http/Controllers/HomeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index abe0b608..7948b663 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -67,7 +67,6 @@ class HomeController extends Controller { if ($daysLeft > 1) return strval(number_format($daysLeft, 0)); return ($hoursLeft < 1 ? $this::TIME_LEFT_OUT_OF_CREDITS_TEXT : strval($hoursLeft)); - } /** Show the application dashboard. */ From cccc4bf9aa1fbc2e73c339b1e5429fc3b722ea55 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Fri, 12 Nov 2021 19:53:12 +0100 Subject: [PATCH 7/7] FIX SPACES AVMG --- app/Http/Controllers/HomeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7948b663..f287aa5e 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -86,7 +86,6 @@ class HomeController extends Controller $bg = $this->getTimeLeftBoxBackground($daysLeft); $boxText = $this->getTimeLeftBoxText($daysLeft, $hoursLeft); $unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : "hours") : "days"; - }