diff --git a/src/TerminalObject/Basic/Table.php b/src/TerminalObject/Basic/Table.php index 6160eb4..1d5e28b 100644 --- a/src/TerminalObject/Basic/Table.php +++ b/src/TerminalObject/Basic/Table.php @@ -110,7 +110,7 @@ private function splitRows($data) $height = 1; $lines = []; foreach ($row as $key => $column) { - $lines[$key] = preg_split('/(\r\n|\r|\n)/u', $column); + $lines[$key] = preg_split('/(\r\n|\r|\n)/u', (string) $column); $height = max($height, count($lines[$key])); } $keys = array_keys($row); diff --git a/src/TerminalObject/Dynamic/Progress.php b/src/TerminalObject/Dynamic/Progress.php index 73516c8..a860b76 100644 --- a/src/TerminalObject/Dynamic/Progress.php +++ b/src/TerminalObject/Dynamic/Progress.php @@ -4,6 +4,9 @@ use League\CLImate\Exceptions\UnexpectedValueException; +use function is_string; +use function strlen; + class Progress extends DynamicTerminalObject { /** @@ -234,7 +237,7 @@ protected function getProgressBar($current, $label) $progress_bar .= $this->getProgressBarStr($current, $label); // If this line has a label then set that this progress bar has a label line - if (strlen($label) > 0) { + if (is_string($label) && strlen($label) > 0) { $this->has_label_line = true; } diff --git a/src/TerminalObject/Helper/StringLength.php b/src/TerminalObject/Helper/StringLength.php index 59751fd..7330258 100644 --- a/src/TerminalObject/Helper/StringLength.php +++ b/src/TerminalObject/Helper/StringLength.php @@ -47,7 +47,7 @@ protected function withoutTags($str) { $this->setIgnoreTags(); - return str_replace($this->ignore_tags, '', $str); + return str_replace($this->ignore_tags, '', (string) $str); } /** diff --git a/tests/TableTest.php b/tests/TableTest.php index 538db03..31d65ca 100644 --- a/tests/TableTest.php +++ b/tests/TableTest.php @@ -274,4 +274,25 @@ public function testTableWithMultipleNewlines() ], ]); } + + + /** + * @doesNotPerformAssertions + */ + public function testTableWithNullAndEmptyValues() + { + $this->shouldWrite("\e[m------------------\e[0m"); + $this->shouldWrite("\e[m| Cell 1 | | |\e[0m"); + $this->shouldWrite("\e[m------------------\e[0m"); + + $this->shouldHavePersisted(); + + $this->cli->table([ + [ + 'Cell 1', + null, + '' + ], + ]); + } }