Skip to content

Commit 4b5c41e

Browse files
committed
Factorized the warning handling method
1 parent 6c44dd5 commit 4b5c41e

File tree

1 file changed

+17
-44
lines changed

1 file changed

+17
-44
lines changed

Step/ItemStep.php

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,7 @@ public function doExecute(StepExecution $stepExecution)
176176
continue;
177177
}
178178
} catch (InvalidItemException $e) {
179-
$stepExecution->addError(
180-
get_class($this->reader),
181-
$e->getMessage(),
182-
$e->getItem()
183-
);
184-
185-
$this->dispatchInvalidItemEvent(
186-
get_class($this->reader),
187-
$e->getMessage(),
188-
$e->getItem()
189-
);
179+
$this->handleStepExecutionWarning($stepExecution, get_class($this->reader), $e);
190180

191181
continue;
192182
}
@@ -203,17 +193,7 @@ public function doExecute(StepExecution $stepExecution)
203193
);
204194
}
205195
} catch (InvalidItemException $e) {
206-
$stepExecution->addError(
207-
get_class($this->processor),
208-
$e->getMessage(),
209-
$e->getItem()
210-
);
211-
212-
$this->dispatchInvalidItemEvent(
213-
get_class($this->processor),
214-
$e->getMessage(),
215-
$e->getItem()
216-
);
196+
$this->handleStepExecutionWarning($stepExecution, get_class($this->processor), $e);
217197

218198
continue;
219199
}
@@ -225,17 +205,7 @@ public function doExecute(StepExecution $stepExecution)
225205
$this->writer->write($itemsToWrite);
226206
$itemsToWrite = array();
227207
} catch (InvalidItemException $e) {
228-
$stepExecution->addError(
229-
get_class($this->writer),
230-
$e->getMessage(),
231-
$e->getItem()
232-
);
233-
234-
$this->dispatchInvalidItemEvent(
235-
get_class($this->processor),
236-
$e->getMessage(),
237-
$e->getItem()
238-
);
208+
$this->handleStepExecutionWarning($stepExecution, get_class($this->writer), $e);
239209

240210
continue;
241211
}
@@ -247,17 +217,7 @@ public function doExecute(StepExecution $stepExecution)
247217
$this->writer->write($itemsToWrite);
248218
$itemsToWrite = array();
249219
} catch (InvalidItemException $e) {
250-
$stepExecution->addError(
251-
get_class($this->writer),
252-
$e->getMessage(),
253-
$e->getItem()
254-
);
255-
256-
$this->dispatchInvalidItemEvent(
257-
get_class($this->processor),
258-
$e->getMessage(),
259-
$e->getItem()
260-
);
220+
$this->handleStepExecutionWarning($stepExecution, get_class($this->writer), $e);
261221
}
262222
}
263223
}
@@ -279,4 +239,17 @@ protected function initializeStepComponents(StepExecution $stepExecution)
279239
$this->writer->setStepExecution($stepExecution);
280240
}
281241
}
242+
243+
/**
244+
* Handle step execution warning
245+
*
246+
* @param StepExecution $stepExecution
247+
* @param string $class
248+
* @param InvalidItemException $e
249+
*/
250+
private function handleStepExecutionWarning(StepExecution $stepExecution, $class, InvalidItemException $e)
251+
{
252+
$stepExecution->addError($class, $e->getMessage(), $e->getItem());
253+
$this->dispatchInvalidItemEvent($class, $e->getMessage(), $e->getItem());
254+
}
282255
}

0 commit comments

Comments
 (0)