diff --git a/app/Enums/ResultStatus.php b/app/Enums/ResultStatus.php index 448dd7237..dc0ea7b0c 100644 --- a/app/Enums/ResultStatus.php +++ b/app/Enums/ResultStatus.php @@ -2,9 +2,10 @@ namespace App\Enums; +use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasLabel; -enum ResultStatus: string implements HasLabel +enum ResultStatus: string implements HasColor, HasLabel { case Completed = 'completed'; // a speedtest that ran successfully. case Failed = 'failed'; // a speedtest that failed to run successfully. @@ -14,4 +15,13 @@ public function getLabel(): ?string { return $this->name; } + + public function getColor(): ?string + { + return match ($this) { + ResultStatus::Completed => 'success', + ResultStatus::Failed => 'danger', + ResultStatus::Started => 'warning', + }; + } } diff --git a/app/helpers.php b/app/helpers.php index b70141cb9..ad3c350a6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -27,7 +27,9 @@ function toBits(float $size, int $precision = 4): float if (! function_exists('percentChange')) { function percentChange(float $dividend, float $divisor, int $precision = 0): string { - if ($dividend === 0 || $divisor === 0) { + try { + $quotient = $dividend / $divisor; + } catch (DivisionByZeroError $e) { return 0; } @@ -73,7 +75,7 @@ function json_validate($data) { if (! empty($data)) { return is_string($data) && - is_array(json_decode($data, true)) ? true : false; + is_array(json_decode($data, true)) ? true : false; } return false;