From 00177a134e6236b83f61d90d0a978c369e14ac4b Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Wed, 28 Jun 2023 14:36:51 +0600 Subject: [PATCH] Introduced ServiceResult and ServiceResultError interfaces, and respective classes with related methods. These changes were necessary to add and handle service results throughout the app. We now have a standard way to return and handle both successes and errors from our services. This leads to cleaner, clearer, and more maintainable code. --- app/Contracts/ServiceResult.php | 9 +++++ app/Contracts/ServiceResultError.php | 12 +++++++ app/ServiceResults/ServiceResult.php | 15 +++++++++ app/ServiceResults/ServiceResultArray.php | 16 +++++++++ app/ServiceResults/ServiceResultError.php | 40 +++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 app/Contracts/ServiceResult.php create mode 100644 app/Contracts/ServiceResultError.php create mode 100644 app/ServiceResults/ServiceResult.php create mode 100644 app/ServiceResults/ServiceResultArray.php create mode 100644 app/ServiceResults/ServiceResultError.php diff --git a/app/Contracts/ServiceResult.php b/app/Contracts/ServiceResult.php new file mode 100644 index 0000000..87f87f6 --- /dev/null +++ b/app/Contracts/ServiceResult.php @@ -0,0 +1,9 @@ +data; + } +} diff --git a/app/ServiceResults/ServiceResultError.php b/app/ServiceResults/ServiceResultError.php new file mode 100644 index 0000000..26f310f --- /dev/null +++ b/app/ServiceResults/ServiceResultError.php @@ -0,0 +1,40 @@ +message; + } + + public function getCode(): ?int + { + return $this->code; + } + + public function getErrors(): array + { + return $this->errors; + } + + public function getData(): array + { + return [ + 'message' => $this->getMessage(), + 'errors' => $this->errors + ]; + } +}