Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[String] Add AbstractString::containsAny()#35936

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromnicolas-grekas:str-contains-any
Mar 16, 2020

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedMar 3, 2020
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

We decided to not have acontains() method because we didn't know how to handle the case where several needles are passed. Buthttps://wiki.php.net/rfc/str_contains made me reconsider this idea and I thinkcontainsAny() works great. WDYT?

Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just asking: why is the parameterstring|string[] $needle instead of...string $needles ?

Thanks!

{
$instance = static::createFromString($string);

$this->assertSame(null !== $instance->indexOf($needle), $instance->containsAny($needle));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does copy pasting the method content here actually test something? Shouldn't we create dedicated providers for this new methods?

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasMar 3, 2020
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's better this way to me, easier to maintain.

@fancyweb
Copy link
Contributor

Just asking: why is the parameter string|string[] $needle instead of ...string $needles ?

I think it's to pass directly (without alteration) the method argument toindexOf.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedMar 3, 2020
edited
Loading

instead of ...string $needles

Clearly, for consistency.

@ro0NL
Copy link
Contributor

containsAny('string') is a step back compared tocontains('string') IMHO.

in this case doescontains(string $needle) + containsAny(array $needles) makes sense?

assuming we dont ever needcontainsAll(array $needles). But if so, it's still possible ... (containsAny('string') + containsAll('string') would be another step back)

alternatively, shouldnt we advice to compose any/all logic in userland based oncontains('string'), it's not likecontains('a') || contains('b') is that bad actually ;) (same forcontains('a') && contains('b')).

@nicolas-grekas
Copy link
MemberAuthor

containsAny('string') is a step back compared to contains('string') IMHO.
in this case does contains(string $needle) + containsAny(array $needles) makes sense?

3 extra letters adding clarity win over a new method to me, especially considering that the class is already a collection of methods. We shouldn't inflate contains*() method in comparison to the other ones.

it's not like contains('a') || contains('b') is that bad actually

You should have a look again at the full interface of the class: several methods already supportstring|string[]. Not doing so for "contains" would be inconsistent.

Doing so is consistent, and useful.

@nicolas-grekas
Copy link
MemberAuthor

Note that I'm fine naming this methodcontains() if that's the broader consensus. Please advise.

ro0NL reacted with thumbs up emoji

@javiereguiluz
Copy link
Member

I think thatcontains() is ambiguous. I will look at it and always wonder ... is it"contains all" or"contains any" ? 🤔

this is the same problem we suffered for years with theis_granted(array $roles) method ... is it"all roles required" or"any role required" ?

@ro0NL
Copy link
Contributor

ro0NL commentedMar 7, 2020
edited
Loading

there'sbefore/after() assuming OR already, is it less ambigious? is contains() specifically the confusing case ... thus worth a containsAny, but not before/afterAny? Is that inconsistent? if so, why dont we mind being inconsistent withcontains(string $needle) also then?

long term, are we really, really, sure about a defacto standard String component/API... without acontains method 🙉

do we really mind adding N*3 methods (single, any, all) IF the case is ambiguous, in favor of clear behavior + type info... is it worth this debate we have?

@nicolas-grekas
Copy link
MemberAuthor

Apparently ppl don't have an issue with before/after. I suppose that's because nobody expects a "beforeAny" or "afterAny". That wouldn't mean anything useful and it intuitively is a beforeAll and afterAll.

the discussion proves that "contains" can be confusing.

I'm therefor confirming that I definitely also prefercontainsAny().

Thanks for raising the point.

javiereguiluz reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit34583b7 intosymfony:masterMar 16, 2020
@nicolas-grekasnicolas-grekas deleted the str-contains-any branchApril 5, 2020 16:59
@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
@fabpotfabpot mentioned this pull requestMay 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@localheinzlocalheinzlocalheinz left review comments

@fancywebfancywebfancyweb left review comments

@fabpotfabpotfabpot approved these changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

7 participants
@nicolas-grekas@fancyweb@ro0NL@javiereguiluz@fabpot@localheinz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp