From a18b984e904370e14744a17aba5c501c6cf14b2b Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 20 Oct 2023 15:53:23 +0200 Subject: [PATCH] Added a way to add rejection reason --- src/PipelineRunner.php | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/PipelineRunner.php b/src/PipelineRunner.php index a61dbbf..cf91107 100644 --- a/src/PipelineRunner.php +++ b/src/PipelineRunner.php @@ -4,6 +4,8 @@ namespace Kiboko\Component\Pipeline; +use Kiboko\Component\Bucket\RejectionResultBucket; +use Kiboko\Component\Bucket\RejectionWithReasonResultBucket; use Kiboko\Contract\Bucket\AcceptanceResultBucketInterface; use Kiboko\Contract\Bucket\RejectionResultBucketInterface; use Kiboko\Contract\Bucket\ResultBucketInterface; @@ -44,17 +46,34 @@ public function run( } if ($bucket instanceof RejectionResultBucketInterface) { - foreach ($bucket->walkRejection() as $line) { - $rejection->reject($line); - $state->reject(); - - $this->logger->log( - $this->rejectionLevel, - 'Some data was rejected from the pipeline', - [ - 'line' => $line, - ] - ); + if ($bucket instanceof RejectionResultBucket) { + foreach ($bucket->walkRejection() as $line) { + $rejection->reject($line); + $state->reject(); + + $this->logger->log( + $this->rejectionLevel, + 'Some data was rejected from the pipeline', + [ + 'line' => $line, + ] + ); + } + } + + if ($bucket instanceof RejectionWithReasonResultBucket) { + foreach ($bucket->walkRejection() as $line) { + $rejection->rejectWithReason($line, $bucket->getReason()); + $state->reject(); + + $this->logger->log( + $this->rejectionLevel, + 'Some data was rejected from the pipeline', + [ + 'line' => $line, + ] + ); + } } }