Skip to content

Commit

Permalink
PHP 8.1 deprecation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sartor authored and duncan3dc committed Oct 30, 2024
1 parent 2cecff8 commit a20112f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/TerminalObject/Basic/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/TerminalObject/Dynamic/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use League\CLImate\Exceptions\UnexpectedValueException;

use function is_string;
use function strlen;

class Progress extends DynamicTerminalObject
{
/**
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/TerminalObject/Helper/StringLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
''
],
]);
}
}

0 comments on commit a20112f

Please sign in to comment.