From c80cd145769c804a2ed907786b1f74d38a1b43f3 Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 20 Oct 2023 15:55:32 +0200 Subject: [PATCH] Added a new bucket to save the reason of a reject --- src/RejectionWithReasonResultBucket.php | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/RejectionWithReasonResultBucket.php diff --git a/src/RejectionWithReasonResultBucket.php b/src/RejectionWithReasonResultBucket.php new file mode 100644 index 0000000..aedbf54 --- /dev/null +++ b/src/RejectionWithReasonResultBucket.php @@ -0,0 +1,36 @@ + + */ +final class RejectionWithReasonResultBucket implements Contract\RejectionResultBucketInterface +{ + public function __construct(private mixed $value, private ?string $reason = null) {} + + public function reject($value, $reason): self + { + $this->value = $value; + $this->reason = $reason; + + return $this; + } + + public function getReason(): ?string + { + return $this->reason; + } + + /** @return iterable */ + public function walkRejection(): iterable + { + return new \ArrayIterator([$this->value]); + } +}