Problem/Motivation
Part of #3324560: Replace strpos/substr with str_starts_with() / str_contains() / str_ends_with().
Proposed resolution
- Replace
strpos($a, $b) === 0withstr_starts_with($a, $b) - Replace
strpos($a, $b) !== 0with!str_starts_with($a, $b) - A few are deliberately omitted where they would cause merge conflicts with other child issues.
Remaining tasks
- When reviewing, consider using
git diff --color-wordsorgit 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

| Comment | File | Size | Author |
|---|---|---|---|
| #12 | Selection_047.png | 85.09 KB | rpayanm |
Issue fork drupal-3328443
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:
- 3328443-strpos-starts-with
changes, plain diff MR !3144
Comments
Comment #2
xjmComment #4
xjmComment #5
xjmComment #6
xjmComment #7
xjmComment #8
xjmComment #9
xjmComment #10
rpayanmThe patch does not apply anymore.
Comment #11
xjmFixed the merge conflict, which was due to some code adopting
str_starts_with()and using a slightly different logic structure than the one in HEAD.Comment #12
rpayanmI reviewed the patch like this:

1. Checked out the branch 10.1.x and pulled the latest changes, applied this patch.
2. Checked the patterns
strpos($haystack, $needle) === 0andstrpos($haystack, $needle, 0) === 0become tostr_starts_with($haystack, $needle). Andstrpos($haystack, $needle) !== 0become!str_starts_with($haystack, $needle). I checked each change visually with a Phpstorm tool (Compare with branch) on every changed line, it looks like this:Everything was fine!
3. Searched for the
strpospatterns mentioned before in the Drupal core code. But I found some changes to be done:core/lib/Drupal/Core/Config/Entity/Query/Query.php:
strpos($id, $value) === 0core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php:
strpos($label, $match) === 0core/lib/Drupal/Core/Config/Entity/Query/Condition.php:
strpos($value, $condition['value']) === 0core/lib/Drupal/Core/ParamConverter/EntityConverter.php:
if (strpos($definition['type'], '{') !== FALSE) {core/modules/image/src/PathProcessor/PathProcessorImageStyles.php:
if (strpos($path, '/' . $directory_path . '/styles/') === 0) {core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php:
if (strpos($path, '//') === 0) {Comment #13
xjmThanks @rpayanm.
These are explicitly excluded from the scope to avoid merge conflicts for the other three sibling merge requests. As per the issue summary:
The idea is to merge these four conflict-free merge requests, then clean up the last dangling references in a final issue. That's why the title starts with "Replace most ..." :)
See #3324560: Replace strpos/substr with str_starts_with() / str_contains() / str_ends_with() for more information.
Comment #14
rpayanmoh! great, so the patch looks good to me.
Comment #15
xjmSaving credits.
Comment #19
xjmAdding credits from the original MR. (All I did was split it up; others created it first.)
Comment #21
catchAll the changes look good. Agreed with doing the easy ones here and stragglers at the end.