-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Add Str::isEmpty() and Str::isNotEmpty() to match API symmetry #57280
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
[12.x] Add Str::isEmpty() and Str::isNotEmpty() to match API symmetry #57280
Conversation
This adds the missing isEmpty() and isNotEmpty() static methods to the Str class to provide symmetry with the Stringable class methods. These are the only is* validation methods that were missing from Str.
Tests cover empty strings, whitespace, zero values, and various string content to ensure proper validation behavior. All tests pass successfully.
So, |
Fair point! Though the same argument applies to other My goal isn't to argue that As a developer switching between both, it's confusing when the validation methods suddenly don't align. 🙂 |
To a certain extent, but the difference is far smaller with your examples, where it can easily be dismissed.
Not everything needs to be just for the sake of symmetry. Especially when it is entirely nonsensical.
Well, there is a clear difference: A |
You're right that I still think the symmetry argument holds value from a DX perspective - when both classes share the same set of validation methods ( I'm aware that my other PR (#57279 for With |
Same here! 🙂
What's the use to have it, just to have it, but nobody uses it? Or where's the person saying "damn, what would I give to have |
If we're to have |
Yeah, that would probably more of a benefit. However, then, we would need to keep API symmetry in mind. For |
I'm not sure if this warrants API symmetry, because |
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions! |
This PR adds the missing
isEmpty()
andisNotEmpty()
static methods to theStr
class to provide symmetry with theStringable
class methods.Changes
Str::isEmpty($value)
methodStr::isNotEmpty($value)
methodMotivation
Currently,
Str
provides variousis*
validation methods (isAscii
,isJson
,isUrl
,isUuid
,isUlid
) but lacksisEmpty
andisNotEmpty
, which are available inStringable
. This creates an API inconsistency where these are the onlyvalidation methods missing from the static interface.
Notes
This is related to #57279, as both PRs work in the same area (increasing API symmetry between
Str
andStringable
). However, I wasn't sure if you want to extendStr
in this regard, as I can see arguments in both directions for having these two methods. I hope submitting 2 separate PRs is okay! 🙂