-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix real text too short #152
Conversation
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
@@ -40,7 +61,31 @@ public function realText($maxNbChars = 200, $indexSize = 2) | |||
throw new \InvalidArgumentException('indexSize must be at most 5'); | |||
} | |||
|
|||
if ($minNbChars >= $maxNbChars) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt we set a minimum here as well? And check for valid values since an -10 can also be passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now added a check that $minNbChars
is not smaller than 1.
It doesn't make much sense to set $minNbChars
to something much smaller than $maxNbChars
, but it also doesn't prevent the algorithm from working as expected (producing real text that is between min and max chars long), so I wouldn't prohibit doing it.
Thank you! |
@krsriq can you please document this? |
@bramceulemans yes, definitely - it's on my todo list :) |
Thanks :) |
What is the reason for this PR?
This PR is related to #37, a more detailed description of the issues observed can be found there.
realText
may produce text that is too short, e.g. by running:which returns
THE.
(even though 2000 characters were requested).Author's checklist
Summary of changes
This PR fixes the issue mentioned above while adding a new
Text::realTextBetween($minNbChars = 160, $maxNbChars = 200, $indexSize = 2)
method (as was suggested in #37).It adds a simple loop to make sure that the returned text from
realText
is at least 80% the length set with$maxNbChars
. The same logic is used to provide therealTextBetween
method.Also made sure we have a maximum number of retries and added tests.
Review checklist