From cdb0cfe36c26eca61cf90fc64708a0997e637a0c Mon Sep 17 00:00:00 2001 From: Michael Diodone <8616698+mdio@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:54:42 +0100 Subject: [PATCH] Fix handling of null in Text::cleanText() Credits to smulvih2 from https://github.com/DaveChild/Text-Statistics/pull/55 --- src/DaveChild/TextStatistics/Text.php | 2 +- tests/TextStatisticsTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DaveChild/TextStatistics/Text.php b/src/DaveChild/TextStatistics/Text.php index 6210848..4c124e3 100644 --- a/src/DaveChild/TextStatistics/Text.php +++ b/src/DaveChild/TextStatistics/Text.php @@ -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 ''; } diff --git a/tests/TextStatisticsTest.php b/tests/TextStatisticsTest.php index 45b57dd..ffde722 100644 --- a/tests/TextStatisticsTest.php +++ b/tests/TextStatisticsTest.php @@ -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.!! !??')); }