Skip to content

Commit

Permalink
Do not pass null to the $text parameter of adapter's notify()
Browse files Browse the repository at this point in the history
The `$text` parameter is documented to take a `string`, not a `?string` and in
fact the Console adapter unconditionally calls a variant of `substr()` on the
given `$text` to shorten it to the configured display width.

With PHP 8.1 this fails, because native functions no longer accept `null` for a
string parameter:

> TypeError: grapheme_substr(): Argument #1 ($string) must be of type string, null given in […]

Signed-off-by: Tim Düsterhus <[email protected]>
  • Loading branch information
TimWolla committed Jul 28, 2022
1 parent 6b97d7d commit c6adc87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProgressBar
*
* @var string
*/
protected $statusText = null;
protected $statusText = '';

/**
* Adapter for the output
Expand Down
7 changes: 7 additions & 0 deletions test/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public function testEtaZeroPercent()
$this->assertEquals(null, $progressBar->getTimeRemaining());
}

public function testMissingTextIsNotNull()
{
$progressBar = $this->_getProgressBar(0, 100);

$this->assertSame('', $progressBar->getText());
}

// @codingStandardsIgnoreStart
protected function _getProgressBar($min, $max, $persistenceNamespace = null)
{
Expand Down

0 comments on commit c6adc87

Please sign in to comment.