From a20112f29623cd66d175e3099a98824f437d21a9 Mon Sep 17 00:00:00 2001 From: Sartor Date: Mon, 21 Feb 2022 16:44:56 +0200 Subject: [PATCH] PHP 8.1 deprecation fixes --- src/TerminalObject/Basic/Table.php | 2 +- src/TerminalObject/Dynamic/Progress.php | 5 ++++- src/TerminalObject/Helper/StringLength.php | 2 +- tests/TableTest.php | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/TerminalObject/Basic/Table.php b/src/TerminalObject/Basic/Table.php index 6160eb4f..1d5e28bb 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 73516c8c..a860b76a 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 59751fdc..73302582 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 538db03f..31d65ca0 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, + '' + ], + ]); + } }