Fix real text too short#152
Merged
pimjansen merged 8 commits intoFakerPHP:mainfrom Dec 19, 2020
Merged
Conversation
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
pimjansen
requested changes
Dec 19, 2020
| throw new \InvalidArgumentException('indexSize must be at most 5'); | ||
| } | ||
|
|
||
| if ($minNbChars >= $maxNbChars) { |
There was a problem hiding this comment.
Shouldnt we set a minimum here as well? And check for valid values since an -10 can also be passed
Author
There was a problem hiding this comment.
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.
pimjansen
approved these changes
Dec 19, 2020
Author
|
Thank you! |
Member
|
@krsriq can you please document this? |
Author
@bramceulemans yes, definitely - it's on my todo list :) |
Member
Thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
realTextmay 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
realTextis at least 80% the length set with$maxNbChars. The same logic is used to provide therealTextBetweenmethod.Also made sure we have a maximum number of retries and added tests.
Review checklist