From 6dd24ac1d390cccbb70ea13259dac875f2a1c583 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Thu, 6 Jul 2023 22:31:39 +0600 Subject: [PATCH] A new method 'isError' has been introduced to the ServiceResult interface and its implementation. This change was made to improve readability and logic. Now instead of checking if the result is not successful, we can directly check if it's an error using isError method. This improves the code clarity. --- app/Contracts/ServiceResult.php | 1 + app/ServiceResults/ServiceResult.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Contracts/ServiceResult.php b/app/Contracts/ServiceResult.php index 87f87f6..1af22ed 100644 --- a/app/Contracts/ServiceResult.php +++ b/app/Contracts/ServiceResult.php @@ -6,4 +6,5 @@ namespace App\Contracts; interface ServiceResult { public function isSuccess(): bool; + public function isError(): bool; } diff --git a/app/ServiceResults/ServiceResult.php b/app/ServiceResults/ServiceResult.php index 826d3a0..6a83939 100644 --- a/app/ServiceResults/ServiceResult.php +++ b/app/ServiceResults/ServiceResult.php @@ -10,6 +10,11 @@ abstract class ServiceResult implements ServiceResultContract { public function isSuccess(): bool { - return $this instanceof ServiceResultErrorContract !== true; + return $this->isError() === false; + } + + public function isError(): bool + { + return $this instanceof ServiceResultErrorContract === true; } }