From e60da678837c70ce1b71b05004ddac8ec7550f8c Mon Sep 17 00:00:00 2001 From: Robert Clochard Date: Thu, 19 Apr 2018 14:03:36 +0200 Subject: [PATCH] Implements null check 4 final rendering TableWriter In case no data was processed, now TableWriter throws an Exception. Better give an output. You are free to change the wording :) --- src/TableWriter.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TableWriter.php b/src/TableWriter.php index c1399e0..c3cb0c5 100644 --- a/src/TableWriter.php +++ b/src/TableWriter.php @@ -46,10 +46,15 @@ public function writeItem(array $item) { /** * {@inheritdoc} */ - public function finish() { - $this->table->setHeaders(array_keys($this->firstItem)); - $this->table->render(); - + public function finish() { + if(!is_null($this->firstItem)) { + $this->table->setHeaders(array_keys($this->firstItem)); + }else{ + $this->table->setHeaders(array('Result')); + $this->table->addRow(array('No items processed.')); + } + + $this->table->render(); $this->firstItem = null; } }