From 23b5c07846e653a82787984060c80ef3cdc90539 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 25 Jul 2026 18:40:11 +0300 Subject: [PATCH] Remove dead code in `StringHelper::truncateWordsByLength()` --- CHANGELOG.md | 1 + src/StringHelper.php | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c33248e..0568207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - New #156: Add `NumericHelper::trimDecimalZeros()` (@samdark, @vjik) - Enh #163: Explicitly import classes, functions, and constants in "use" sections (@vjik) +- Enh #167: Remove dead code in `StringHelper::truncateWordsByLength()` (@vjik) ## 2.7.0 November 23, 2025 diff --git a/src/StringHelper.php b/src/StringHelper.php index 03bb8f3..a1a8fb7 100644 --- a/src/StringHelper.php +++ b/src/StringHelper.php @@ -382,10 +382,8 @@ public static function truncateWordsByLength( // Prefer not to break words if there's a space within the snippet. $lastSpace = mb_strrpos($truncated, ' ', 0, $encoding); if ($lastSpace !== false) { - $cut = rtrim(mb_substr($truncated, 0, $lastSpace, $encoding)); - return $cut === '' - ? mb_substr($trimMarker, 0, $length, $encoding) - : $cut . $trimMarker; + return rtrim(mb_substr($truncated, 0, $lastSpace, $encoding)) + . $trimMarker; } return $truncated . $trimMarker;