From 9f162451ffa6f52dff05572ec6fc8bc48a8c3b92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Feb 2026 04:44:39 +0000 Subject: [PATCH 1/2] Initial plan From 057a86d5499bca912485a65962873419294961f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Feb 2026 04:54:01 +0000 Subject: [PATCH 2/2] Fix undefined array key in Syllables by normalizing whitespace before explode Co-authored-by: pattonwebz <3902039+pattonwebz@users.noreply.github.com> --- src/DaveChild/TextStatistics/Syllables.php | 2 ++ tests/TextStatisticsTest.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/DaveChild/TextStatistics/Syllables.php b/src/DaveChild/TextStatistics/Syllables.php index 0ae6edd..4c6d09e 100644 --- a/src/DaveChild/TextStatistics/Syllables.php +++ b/src/DaveChild/TextStatistics/Syllables.php @@ -356,6 +356,7 @@ public static function totalSyllables($strText, $strEncoding = '') public static function averageSyllablesPerWord($strText, $strEncoding = '') { $intSyllableCount = 0; + $strText = preg_replace('/\s+/', ' ', trim($strText)); $intWordCount = Text::wordCount($strText, $strEncoding); $arrWords = explode(' ', $strText); for ($i = 0; $i < $intWordCount; $i++) { @@ -375,6 +376,7 @@ public static function averageSyllablesPerWord($strText, $strEncoding = '') public static function wordsWithThreeSyllables($strText, $blnCountProperNouns = true, $strEncoding = '') { $intLongWordCount = 0; + $strText = preg_replace('/\s+/', ' ', trim($strText)); $intWordCount = Text::wordCount($strText, $strEncoding); $arrWords = explode(' ', $strText); for ($i = 0; $i < $intWordCount; $i++) { diff --git a/tests/TextStatisticsTest.php b/tests/TextStatisticsTest.php index 45b57dd..023f4bf 100644 --- a/tests/TextStatisticsTest.php +++ b/tests/TextStatisticsTest.php @@ -192,6 +192,28 @@ public function testAverageSyllablesPerWord() $this->assertEquals(1, $this->TextStatistics->averageSyllablesPerWord('and then there was one')); $this->assertEquals(2, $this->TextStatistics->averageSyllablesPerWord('because special ducklings deserve rainbows')); $this->assertEquals(1.5, $this->TextStatistics->averageSyllablesPerWord('and then there was one because special ducklings deserve rainbows')); + // Regression: non-space whitespace must not cause undefined array key warnings + $this->assertEquals( + $this->TextStatistics->averageSyllablesPerWord('and then'), + $this->TextStatistics->averageSyllablesPerWord("and\nthen") + ); + $this->assertEquals( + $this->TextStatistics->averageSyllablesPerWord('and then'), + $this->TextStatistics->averageSyllablesPerWord("and\tthen") + ); + $this->assertEquals( + $this->TextStatistics->averageSyllablesPerWord('and then'), + $this->TextStatistics->averageSyllablesPerWord("and\n\nthen") + ); + } + + public function testWordsWithThreeSyllablesWhitespace() + { + // Regression: non-space whitespace must produce the same result as spaces + $this->assertEquals( + DaveChild\TextStatistics\Syllables::wordsWithThreeSyllables('there is just one', true), + DaveChild\TextStatistics\Syllables::wordsWithThreeSyllables("there\nis\njust\none", true) + ); } /* Test Words