Problem/Motivation

Part of #3324560: Replace strpos/substr with str_starts_with() / str_contains() / str_ends_with().

Proposed resolution

  1. Replace strpos($a, $b) !== FALSE with str_contains($a, $b)
  2. Replace strpos($a, $b) === FALSE with !str_contains($a, $b)
  3. A few are deliberately omitted where they would cause merge conflicts with other child issues.

Remaining tasks

  • When reviewing, consider using git diff --color-words or git diff --porecelain.
  • Pay attention to the !. It should be in the expression once either before the change or after the change.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3328454

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

xjm created an issue. See original summary.

xjm’s picture

Title: Replace most strpos() !== FALSE with str_contains() » Replace most strpos() !== FALSE or === FALSE with str_contains()

xjm’s picture

Status: Active » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new150 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Bhanu951 made their first commit to this issue’s fork.

xjm’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

bhanu951’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new53.37 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nod_’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot

While I'll look into it

xjm’s picture

There was a merge conflict due to #3328454: Replace most strpos() !== FALSE or === FALSE with str_contains() moving a line we're changing to a different file. Addressed with the latest merge.

xjm’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Been avoiding this ticket a week haha

Finally got around to reviewing, searching for strpos( and reviewing each found a few files

PathProcessorImageStyles (few instances)
BookJavascriptTest (not sure if tests are included)
UserNameConstraintValidator

jidrone made their first commit to this issue’s fork.

jidrone’s picture

Status: Needs work » Needs review

Hi,

I added the cases mentioned by @smustgrave and others that I found.

I'm only taking into account the following patterns as suggested in the description:

  • strpos($a, $b) !== FALSE
  • strpos($a, $b) === FALSE

I was not including:

  • ($pos = strpos($input, '@', $pos)) !== false
  • ($start = strpos($message, '{')) !== FALSE
  • strpos($value, $condition['value']) === 0
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

I think not including is correct. Think that would make the scope of this too large IMO. This looks good!

catch’s picture

Status: Reviewed & tested by the community » Needs work

There are at least two changes to str_starts_with(), which isn't the scope defined in #16. All the in-scope changes look fine, but let's please limit the MR to those, makes it a lot harder to scan the hundreds of lines of diff if there are multiple patterns dealt with at once.

Note to self: got down to AliasPathProcessor

jidrone’s picture

Status: Needs work » Needs review

Reverted the 2 cases that were not strpos replacements.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @catch for the review.

  • catch committed b3fac4a0 on 10.1.x
    Issue #3328454 by xjm, Bhanu951, jidrone, smustgrave: Replace most...
catch’s picture

Status: Reviewed & tested by the community » Fixed

I'm getting a phpstan error trying to commit this locally, which I don't think is the patch but I sometimes see weird failures from phpstan when it runs on particular files.

I've committed this with --no-verify, and if I'm wrong, well mea culpa.

Committed b3fac4a and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.