Repository navigation
Conversation
… or radius is odd
neznaika0
left a comment
There was a problem hiding this comment.
If you are approved to change excerpt() by running the command again, this is considered a change. It should be written in docs.
|
Overall, this is a solid and much-needed fix. Resolving the Here is feedback addressing the review comments and the PR: 1. Fallback vs. Throwing an ExceptionFalling back to extracting from the beginning (
2. The Missing Character Bug (
|
|
Thanks for the review @neznaika0 and @gr8man! I pushed a small update:
Agreed on keeping the missing-character quirk ( |
Description
Because
system/Helpers/text_helper.phpusesdeclare(strict_types=1),excerpt()previously threw an unhandledTypeErrorin two scenarios:$phrasewas passed but did not exist in$text,mb_stripos($text, $phrase)returnedfalse, causingmb_substr($text, 0, $phrasePosition)to fail withTypeError: mb_substr(): Argument #3 ($length) must be of type ?int, bool given.$phrasewasnulland$radiuswas an odd integer (e.g.,101),$radius / 2evaluated tofloat(50.5), causingmb_substr($text, 0, $phrasePosition)to fail withTypeError: mb_substr(): Argument #3 ($length) must be of type ?int, float given.This PR:
excerpt($text, null, $radius, $ellipsis)(extracting from the beginning of$text) when$phrasePosition === false.intdiv($radius, 2)so$phrasePositionis always an integer.docs/helpers/text_helper.mdto document the fallback behavior when$phraseis not found.TextHelperTest(testExcerptPhraseNotFound()andtestExcerptOddRadius()).Checklist: