From a5b6d2982b84fb6bc0e833a148e9f2ddc4976e3d Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 28 Aug 2025 23:01:16 +0200 Subject: [PATCH] Add checking when adding a stage class string --- src/Pipeline/OptionsProcessor/OptionsStageBuilder.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Pipeline/OptionsProcessor/OptionsStageBuilder.php b/src/Pipeline/OptionsProcessor/OptionsStageBuilder.php index 9b5ea07..bfb0ccf 100644 --- a/src/Pipeline/OptionsProcessor/OptionsStageBuilder.php +++ b/src/Pipeline/OptionsProcessor/OptionsStageBuilder.php @@ -22,7 +22,13 @@ class OptionsStageBuilder public function add(string|OptionsStageInterface $stageClass): self { if (is_string($stageClass)) { - $this->stages[] = $this->bag->get($stageClass); + if (new \ReflectionClass($stageClass)->implementsInterface(OptionsStageInterface::class)) { + $this->stages[] = $this->bag->get($stageClass); + } else { + throw new \InvalidArgumentException( + sprintf('Stage must be an instance of OptionsStageInterface, %s given', get_debug_type($stage)) + ); + } } else { $this->stages[] = $stageClass; } @@ -41,4 +47,4 @@ class OptionsStageBuilder { return new ItemsOptionsPipeline(new OptionsProcessor($this->options), ...$this->stages); } -} \ No newline at end of file +}