From c4b09489a48157f8464979b5486a21942dcc260e Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 18 Apr 2024 14:01:21 +0200 Subject: [PATCH] feat: convert result types to enums --- app/Enums/ScanResultType.php | 10 +++++++++ app/Values/ScanResult.php | 42 ++++++++++++------------------------ 2 files changed, 24 insertions(+), 28 deletions(-) create mode 100644 app/Enums/ScanResultType.php diff --git a/app/Enums/ScanResultType.php b/app/Enums/ScanResultType.php new file mode 100644 index 00000000..4a488389 --- /dev/null +++ b/app/Enums/ScanResultType.php @@ -0,0 +1,10 @@ +type === self::TYPE_SUCCESS; + return $this->type === ScanResultType::SUCCESS; } public function isSkipped(): bool { - return $this->type === self::TYPE_SKIPPED; + return $this->type === ScanResultType::SKIPPED; } public function isError(): bool { - return $this->type === self::TYPE_ERROR; + return $this->type === ScanResultType::ERROR; } public function isValid(): bool @@ -57,15 +50,8 @@ final class ScanResult public function __toString(): string { - $type = match ($this->type) { - self::TYPE_SUCCESS => 'Success', - self::TYPE_ERROR => 'Error', - self::TYPE_SKIPPED => 'Skipped', - default => throw new Exception('Invalid type'), - }; + $name = $this->type->value . ': ' . $this->path; - $str = $type . ': ' . $this->path; - - return $this->isError() ? $str . ' - ' . $this->error : $str; + return $this->isError() ? $name . ' - ' . $this->error : $name; } }