Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
base system
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Reporter:
Created:
30 Nov 2022 at 13:11 UTC
Updated:
29 Apr 2024 at 05:44 UTC
Jump to comment: Most recent
PHPStorm can automatically replace strpos and substr with the applicable PHP 8 function for more readable and easier to grok code.
Run the PHPStorm scanner and fixer.
Do it. Decide if we want to backport to Drupal 9.5 (we have a polyfil).
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
Comment #3
alexpottThis change will need https://www.drupal.org/project/drupal/issues/3324540 to land because it change locale.module and that has a PHPCS issue in it.
Comment #4
alexpottComment #5
longwaveOverall this looks good, but a couple of questions about vendor-copied code. Also this is probably disruptive to other patches given it touches a large number of files, so I think either we do it now to all active branches (including 9.5.x to make backports easier) or we wait until the beta window of 10.1.x and do it then.
Comment #6
alexpottI'm not convinced - it's single line changes in a few files. Given now we have MRs if people use them this type of change is not actually disruptive.
Comment #7
longwaveAlso is this worth raising a coding standards issue over? Coder could prevent this from creeping back in, I guess.
Comment #8
alexpottRe coding standards - if there was a PHPCS rule that we could just enable - or something in PHPStan then sure but I don't think this is worth our time to implement ourselves.
Re files from other projects I think given that there is no logic change here I think it is fine to change them. If we copied them back again we could either re-do the changes or not - as the logic is the same I think it doesn't really matter.
Comment #9
longwaveOK, points taken. This definitely makes things more readable in many cases so I think we should try to get this in.
FWIW I couldn't find anything for PHPCS but PHP-CS-Fixer does have a rule for it: https://cs.symfony.com/doc/rules/alias/modernize_strpos.html - but adopting that is a whole other can of worms to open.
I think if we are to do this we should backport as well to keep things in sync as much as possible, helping us avoid separate patches for future bug fixes.
Comment #11
catchRemoving commit credit for a rebase-only change to the MR.
Found one out of scope change, maybe phpstan being greedy?
Comment #12
longwaveThe out of scope change is due to PHPStorm automatically changing
list()to[].We fixed it once across core in #3222769: [November 8, 2021] Replace all list (array destructuring) assignment to the array syntax
Then it was accidentally reverted again in #3181778: [w/c September 17th] Replace t() with $this->t() in all plugins
This is the only instance of
list()in core so I think we should let this slide and fix it again here.Comment #13
xjmHm, I might've split this into two MRs. 282 lines is sort of on the outer edge for multiple replace patterns. That said, it'd be more work at this point to split it than to just spend the extra time reviewing the different patterns.
The random
list()really gets to me though. So I made #3327950: Remove last remaining list() from core. :PComment #14
xjmOK actually I'm definitely feeling directed attention fatigue with the multiple replace patterns. I'll update the MR after #3327950: Remove last remaining list() from core lands since I'm the one advocating that it should have its own commit. When I do that, I might also split up the MR up myself -- if nothing else, that will help me concentrate on the changes.
Comment #15
xjmWorking on it now.
Comment #16
xjmOne question: Should we actually be changing the code in
Drupal\Component\Annotation\Doctrine? It's ignored for phpcs purposes.Comment #17
xjmComment #18
xjmComment #21
dimitriskr commentedUpdated remaining tasks. No other references are found.
I saw that in some previous commits, some preg_match() was switched with str_starts_with(). I didn't check other instances of preg_match() that could be replaces with these new functions.
Comment #22
dimitriskr commentedComment #23
mstrelan commentedI decided to check with rector if it could find any more to replace. I applied the rules StrContainsRector, StrStartsWithRector and StrEndsWithRector. It found one additional file to update, which I have pushed a commit for. The change replaces
strpos() !== FALSEwithstr_contains(substr())which means more function calls, but I think these are more readable than before. Happy to revert if others disagree.Comment #24
dimitriskr commentedHey mstrelan,
Thank you for looking into this issue
I don't see a commit pushed to this branch/MR
Comment #25
mstrelan commentedAh I forgot to request push access. Have pushed now.
Comment #27
mstrelan commentedRebased against latest 11.x and also push an 11.x branch to the fork to workaround ci issues with spell check job.
Comment #28
catchThis looks good, it's no longer touching the Doctrine forked code, can't see anything to complain about.
Comment #29
quietone commentedShorten the title
Comment #32
quietone commentedI also didn't find anything here to prevent this being committed.
Committed d74c1ca and pushed to 11.x and e5ce10b and pushed to 10.3.x. Thanks!