Problem/Motivation

There are some preg_match calls that can be replaced with either str_starts_with(),str_ends_with() or similar. PHPStorm has an inspection that runs this check automatically to most cases

Steps to reproduce

Proposed resolution

Do it

Remaining tasks

TBD

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3414568

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

dimitriskr created an issue. See original summary.

dimitriskr’s picture

Title: Replace preg_match() with PHP 8's str_starts_with()/str_ends_with() » Replace preg_match() with PHP 8's str_starts_with()/str_ends_with() or similar
Issue summary: View changes
dimitriskr’s picture

Status: Active » Needs review
smustgrave’s picture

Could you post the regex you used to find those?

dimitriskr’s picture

It was a PHPStorm inspection that identified the changes and not manually, so I got no regex for you

dimitriskr’s picture

Maybe something like this? Only for str_ends_with() replacements
https://regex101.com/r/cd29ZX/1

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks used that with also phpstorm (preg_match\('\/.*) got several 100 matches but reviewed a few dozen and didn't find any additional ones that were being suggested to replace.

quietone’s picture

Title: Replace preg_match() with PHP 8's str_starts_with()/str_ends_with() or similar » Replace preg_match() with str_starts_with()/str_ends_with() or similar

I'm triaging RTBC issues. I read the IS, the comments and the MR. I didn't find any unanswered questions.

I ran the inspection in PHPStorm which reported 6 problems in 4 files. Those are fixed here. There are two more changes here, one for \Drupal\Tests\views\Functional\Plugin\PagerTest::testNoLimit and the other in \Drupal\Tests\ComposerIntegrationTest::testComposerLockHash. How were these last two discovered?

I used the grep string from #8 which reports 138 matches in core. There may be more that can be changed but that should not prevent this improvement. We can also do a 'round 2'.

Leaving at RTBC;

dimitriskr’s picture

For ComposerIntegrationTest, I asked in Slack if the replacement was valid, got only one positive response so I committed it.

As for the PagerTest, it came from a related issue and specifically this commit which was reverted there and added here

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 4d5abf7f08 to 11.x and cc7590905b to 10.3.x. Thanks!

  • alexpott committed cc759090 on 10.3.x
    Issue #3414568 by dimitriskr, smustgrave, quietone: Replace preg_match...

  • alexpott committed 4d5abf7f on 11.x
    Issue #3414568 by dimitriskr, smustgrave, quietone: Replace preg_match...

Status: Fixed » Closed (fixed)

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