From 6ae866003b0fdd6212e3671119347154214d6899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1gi-Kaz=C3=A1r=20M=C3=A1rk?= Date: Tue, 14 Jul 2015 00:31:46 +0200 Subject: [PATCH] Remove return type dependency of filter step --- spec/Step/FilterStepSpec.php | 2 +- src/Exception/FilterException.php | 15 +++++++++++++++ src/Step/FilterStep.php | 3 ++- src/StepAggregator.php | 7 ++++--- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/Exception/FilterException.php diff --git a/spec/Step/FilterStepSpec.php b/spec/Step/FilterStepSpec.php index 5c0fd8e..062ac87 100644 --- a/spec/Step/FilterStepSpec.php +++ b/spec/Step/FilterStepSpec.php @@ -43,7 +43,7 @@ function it_processes_and_filters_an_item(Step $step) return false; })->shouldReturn($this); - $this->process( + $this->shouldThrow('Port\Steps\Exception\FilterException')->duringProcess( $item, function($item) use ($step, $next) { return $step->process($item, $next); diff --git a/src/Exception/FilterException.php b/src/Exception/FilterException.php new file mode 100644 index 0000000..acad6ad --- /dev/null +++ b/src/Exception/FilterException.php @@ -0,0 +1,15 @@ + + */ +class FilterException extends \Exception implements Exception +{ + +} diff --git a/src/Step/FilterStep.php b/src/Step/FilterStep.php index 11a8cc0..9e80237 100644 --- a/src/Step/FilterStep.php +++ b/src/Step/FilterStep.php @@ -2,6 +2,7 @@ namespace Port\Steps\Step; +use Port\Steps\Exception\FilterException; use Port\Steps\Step; /** @@ -39,7 +40,7 @@ public function process($item, callable $next) { foreach (clone $this->filters as $filter) { if (false === call_user_func($filter, $item)) { - return false; + throw new FilterException(); } } diff --git a/src/StepAggregator.php b/src/StepAggregator.php index c3d1d93..daa714d 100644 --- a/src/StepAggregator.php +++ b/src/StepAggregator.php @@ -9,6 +9,7 @@ use Port\Workflow; use Port\Writer; use Port\Steps\Exception\BreakException; +use Port\Steps\Exception\FilterException; use Psr\Log\LoggerInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; @@ -114,9 +115,9 @@ public function process() // Read all items foreach ($this->reader as $index => $item) { try { - if (false === $pipeline($item)) { - continue; - } + $pipeline($item); + } catch(FilterException $e) { + continue; } catch(BreakException $e) { break; } catch(Exception $e) {