Skip to content

Commit

Permalink
fix(validator): resolve processor state retention issues
Browse files Browse the repository at this point in the history
Add reset capabilities to validator processors to prevent state leakage
between validations. This resolves the issue where validation errors
were persisting across multiple validation cycles.

- Add reset() method to ValidatableProcessor interface
- Implement reset() in AbstractValidatorProcessor
- Update ProcessorPipeline to call reset() before processing
- Add proper documentation for new methods
  • Loading branch information
walmir-silva committed Oct 24, 2024
1 parent 1d79011 commit dfd371c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/ProcessorPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use KaririCode\Contract\Processor\Pipeline;
use KaririCode\Contract\Processor\Processor;
use KaririCode\Contract\Processor\ValidatableProcessor;

class ProcessorPipeline implements Pipeline
{
Expand All @@ -22,7 +23,14 @@ public function process(mixed $input): mixed
{
return array_reduce(
$this->processors,
fn ($carry, Processor $processor) => $processor->process($carry),
static function ($carry, Processor $processor): mixed {
// Reset the processor's state if it's a ValidatableProcessor
if ($processor instanceof ValidatableProcessor) {
$processor->reset();
}

return $processor->process($carry);
},
$input
);
}
Expand Down

0 comments on commit dfd371c

Please sign in to comment.