Skip to content
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

[11.x] Add containsNone in the Str and Stringable support classes #51383

Closed

Conversation

hameedraha
Copy link

@hameedraha hameedraha commented May 11, 2024

This PR adds a complementary containsNone() function to the String and Stringable helper. This function supports the inverted logic of containsAll(). This is a non-breaking change as it introduces a new function with a similar signature.

Str::containsNone('Laravel is a fantastic framework', ['Fluff', 'Bloat']); // true
Str::of('Laravel is a fantastic framework')->containsNone(['Fluff', 'Bloat'], true); // true

✅ Backward compatible: Added as a new function with an already familiar signature
✅ Reviewed the existing PR (#40396) closed because of the naming confusion, so carefully chose containsNone
✅ Added under both Str and Stringable support classes
✅ Included tests for both functions
✅ PR submitted to the current branch since non-breaking change
✅ Added a clever wordplay in the example provided 😉

@Muetze42
Copy link
Contributor

Why not just like that?

! Str::containsAll('Laravel is a fantastic framework', ['Fluff', 'Bloat']);

@hameedraha
Copy link
Author

hameedraha commented May 11, 2024

Yes, it can definitely be done. As mentioned in the PR referenced, "...which allows the developer to write more expressive code." Not direct comparison, it is similar to abort_if and abort_unless. It will also be helpful during Stringable method chaining.

@johanrosenson
Copy link
Contributor

Why not just like that?

! Str::containsAll('Laravel is a fantastic framework', ['Laravel', 'Bloat']);

This is not comparable to containsNone and the original description given by @hameedraha is actually wrong as well; containsNone is not "the inverted logic of containsAll".

! Str::containsAll('Laravel is a fantastic framework', ['Laravel', 'Bloat']) // true

Str::containsAll('Laravel is a fantastic framework', ['Laravel', 'Bloat']) // false

Str::containsNone('Laravel is a fantastic framework', ['Laravel', 'Bloat']) // false

@hameedraha
Copy link
Author

That's clear. I overlooked it. Thanks for the clarification @johanrosenson

@Muetze42
Copy link
Contributor

@johanrosenson
The answer refers to the description of the function:

This function supports the inverted logic of containsAll()

Inverted logic method to contains would be more appropriate the function:

! Str::contains('Laravel is a fantastic framework', ['Fluff', 'Bloat'], true);  // true

@taylorotwell
Copy link
Member

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 possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants