Skip to content

Commit 140e76f

Browse files
committed
Fix handling of null in Text::cleanText()
Credits to smulvih2 from DaveChild#55
1 parent b1d4bf3 commit 140e76f

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/DaveChild/TextStatistics/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function cleanText($strText)
2020
{
2121

2222
// Check for boolean before processing as string
23-
if (is_bool($strText)) {
23+
if (is_bool($strText) || is_null($strText)) {
2424
return '';
2525
}
2626

tests/TextStatisticsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function tearDown(): void
2828
-------------------- */
2929
public function testCleaning()
3030
{
31+
$this->assertSame('', DaveChild\TextStatistics\Text::cleanText(null));
3132
$this->assertSame('', DaveChild\TextStatistics\Text::cleanText(false));
3233
$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.!! !??'));
3334
}

0 commit comments

Comments
 (0)