(feat) Add blank, filled, with, rescue, retry and benchmark helpers - #344
Open
techmahedy wants to merge 1 commit into
Open
techmahedy wants to merge 1 commit into
techmahedy wants to merge 1 commit into
Conversation
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.
Pull Request Checklist
Description
Summary
Adds six global helper functions to
helpers.php. Each is wrapped infunction_exists, so an application that already defines one of them is unaffected.New helpers
blank($value)null, empty or whitespace-only strings, empty arrays and emptyCountableobjects.0,0.0,'0'andfalseare not blank, unlikeempty().filled($value)blank().with($value, $callback = null)tap(), which always returns the original value.rescue($callback, $default = null, $report = true)$defaultif the callback throws. A Closure default receives the exception. The exception is logged unless$reportis false, and a failing logger does not hide the fallback value.retry($times, $callback, $sleepMs = 0, $when = null)$timesattempts and passes it the attempt number (from 1). Rethrows the last exception when all attempts fail.$sleepMsmay be a Closure for backoff.$whenreturns false to stop retrying and rethrow at once.$timesbelow 1 throwsInvalidArgumentException.benchmark($callback)result,time_ms,memory_bytesandpeak_memory_bytes. Exceptions are not caught.Docs
helpers.mdin the docs repo has a section for each helper and they are added to the Core Helpers indexChecklist