Skip to content

Commit 8ba6b8e

Browse files
committed
fix(Helpers): use intdiv() and document excerpt() fallback
1 parent b408197 commit 8ba6b8e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎docs/helpers/text_helper.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ this_string_is_e…ak_my_design.jpg
489489

490490
This function will extract `$radius` number of characters before and after the central `$phrase` with an ellipsis before and after.
491491

492-
The first parameter is the text to extract an excerpt from, and the second is the central word or phrase to count before and after. The third parameter is the number of characters to count before and after the central phrase. If no phrase is passed, the excerpt will include the first `$radius` characters with the ellipsis at the end.
492+
The first parameter is the text to extract an excerpt from, and the second is the central word or phrase to count before and after. The third parameter is the number of characters to count before and after the central phrase. If no phrase is passed, or if the phrase is not found in the text, the excerpt will include the first `$radius` characters with the ellipsis at the end.
493493

494494
Example:
495495

‎system/Helpers/text_helper.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ function alternator(...$args): string
709709
* @param int $radius The amount of characters returned around the phrase.
710710
* @param string $ellipsis Ending that will be appended
711711
*
712-
* If no $phrase is passed, will generate an excerpt of $radius characters
713-
* from the beginning of $text.
712+
* If no $phrase is passed or $phrase is not found, will generate an excerpt
713+
* of $radius characters from the beginning of $text.
714714
*/
715715
function excerpt(string $text, ?string $phrase = null, int $radius = 100, string $ellipsis = '...'): string
716716
{
@@ -722,7 +722,7 @@ function excerpt(string $text, ?string $phrase = null, int $radius = 100, string
722722
return excerpt($text, null, $radius, $ellipsis);
723723
}
724724
} else {
725-
$phrasePosition = (int) ($radius / 2);
725+
$phrasePosition = intdiv($radius, 2);
726726
$phraseLength = 1;
727727
}
728728

0 commit comments

Comments
 (0)