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

[8.x] Add complimentary Str::doesntContain #40396

Closed
wants to merge 3 commits into from

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Jan 13, 2022

Similar to the recent additions to the Collection class, this PR adds a complimentary doesntContain method. This may be used to test a string does not contain a substring or set of substrings, which allow the developer to write more expressive code.

Before

if (! Str::contains('foo', 'bar')) {
    // ...
}

if (! Str::containsAll('foo', ['bar', 'baz'])) {
    // ...
}

After

if (Str::doesntContain('foo', 'bar')) {
    // ...
}

if (Str::doesntContain('foo', ['bar', 'baz'])) {
    // ...
}

@nunomaduro nunomaduro changed the title Add complimentary contain methods to Str class [8.x] Add complimentary contain methods to Str class Jan 13, 2022
@jasonmccreary jasonmccreary changed the title [8.x] Add complimentary contain methods to Str class [8.x] Add complimentary Str::doesntContain Jan 13, 2022
@foremtehan
Copy link
Contributor

Can you also add those to Stringable class ? https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Stringable.php

@jasonmccreary
Copy link
Contributor Author

@foremtehan, you got it.

@taylorotwell
Copy link
Member

Going to hold off on this for now - mainly because the wording around it confuses my brain when I start thinking about possible methods for a method that would determine if a string doesn't contain at least one of the given strings.

@jasonmccreary jasonmccreary deleted the doesnt-contain branch January 14, 2022 20:53
@jasonmccreary jasonmccreary restored the doesnt-contain branch January 14, 2022 20:53
@jasonmccreary
Copy link
Contributor Author

jasonmccreary commented Jan 14, 2022

No problem. Negated methods can be rather mind bending. Especially with parameter overloading like this one.

I really only chose this name because you used it for the same method on the Collection class. I'd probably have called it missing, doesntContainAny, or doesntInclude.

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.

3 participants