Skip to content

Commit

Permalink
Fix handling of null in Text::cleanText()
Browse files Browse the repository at this point in the history
Credits to smulvih2 from DaveChild#55
  • Loading branch information
mdio committed Nov 10, 2023
1 parent b1d4bf3 commit cdb0cfe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DaveChild/TextStatistics/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function cleanText($strText)
{

// Check for boolean before processing as string
if (is_bool($strText)) {
if (is_bool($strText) || is_null($strText)) {
return '';
}

Expand Down
1 change: 1 addition & 0 deletions tests/TextStatisticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function tearDown(): void
-------------------- */
public function testCleaning()
{
$this->assertSame('', DaveChild\TextStatistics\Text::cleanText(null));
$this->assertSame('', DaveChild\TextStatistics\Text::cleanText(false));
$this->assertSame('There once was a little sausage named Baldrick. and he lived happily ever after.', DaveChild\TextStatistics\Text::cleanText('There once was a little sausage named Baldrick. . . . And he lived happily ever after.!! !??'));
}
Expand Down

0 comments on commit cdb0cfe

Please sign in to comment.