Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add polyfills for str_starts_with() and str_ends_with() to prevent fatal errors in PHP < 8.0 #2992

Merged
merged 1 commit into from Nov 14, 2023

Conversation

justlevine
Copy link
Collaborator

What does this implement/fix? Explain your changes.

Adds PHP 8.0 polyfills for str_starts_with() and str_ends_with().

We're only using str_ends_with() locally, the former is added preemptively since if a dev sees one, theyre going to assume they dont see the other.

Does this close any currently open issues?

Fixes #2991

Any relevant logs, error output, GraphiQL screenshots, etc?

Any other comments?

It's not getting picked up by PHPCompatibilityWP because our other dev-deps install symfony's polyfill package, so even on <8.0 the method exists on all dev environments.

Where has this been tested?

Operating System: Ubuntu 20.04 (Wsl2 + devilbox + php 8.1.15)

WordPress Version: 6.4.1

Polyfills added for `str_starts_with` and `str_ends_with`.
@justlevine justlevine added Type: Bug Something isn't working php Pull requests that update Php code labels Nov 11, 2023
* @param string $haystack
* @param string $needle
*/
function str_ends_with( string $haystack, string $needle ): bool {
Copy link

Choose a reason for hiding this comment

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

Function str_ends_with has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

Copy link

codeclimate bot commented Nov 11, 2023

Code Climate has analyzed commit 5d94410 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@justlevine justlevine changed the title fix: add polyfills for PHP 8.0 fix: add polyfills for str_starts_with() and str_ends_with() to prevent fatal errors in PHP < 8.0 Nov 11, 2023
@coveralls
Copy link

Coverage Status

coverage: 84.723%. remained the same
when pulling 5d94410 on justlevine:fix/polyfill-str_ends_with
into b3b83e7 on wp-graphql:develop.

Copy link
Collaborator

@jasonbahl jasonbahl left a comment

Choose a reason for hiding this comment

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

Thanks @justlevine! 🙌🏻

@jasonbahl jasonbahl merged commit 48a4720 into wp-graphql:develop Nov 14, 2023
27 of 29 checks passed
@justlevine justlevine deleted the fix/polyfill-str_ends_with branch November 14, 2023 18:15
@jasonbahl jasonbahl mentioned this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
php Pull requests that update Php code Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal error in WPConnectionType when calling str_ends_with() on PHP < 8.0
3 participants