Skip to content

Eliminate usage of empty() construct#1803

Merged
westonruter merged 18 commits intoWordPress:trunkfrom
ShyamGadde:fix/eliminate-empty-usage
Jan 28, 2025
Merged

Eliminate usage of empty() construct#1803
westonruter merged 18 commits intoWordPress:trunkfrom
ShyamGadde:fix/eliminate-empty-usage

Conversation

@ShyamGadde
Copy link
Copy Markdown
Contributor

Summary

Fixes #1219

Relevant technical choices

This PR eliminates the use of empty() in the following plugins:

  • dominant-color-images
  • performance-lab
  • webp-uploads

@ShyamGadde ShyamGadde added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) no milestone PRs that do not have a defined milestone for release [Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only labels Jan 16, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 78.37838% with 16 lines in your changes missing coverage. Please review.

Project coverage is 65.89%. Comparing base (3ce0f45) to head (2a93cf4).
Report is 19 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/webp-uploads/hooks.php 73.68% 10 Missing ⚠️
plugins/webp-uploads/deprecated.php 0.00% 5 Missing ⚠️
plugins/dominant-color-images/hooks.php 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1803      +/-   ##
==========================================
+ Coverage   65.85%   65.89%   +0.03%     
==========================================
  Files          88       88              
  Lines        6851     6878      +27     
==========================================
+ Hits         4512     4532      +20     
- Misses       2339     2346       +7     
Flag Coverage Δ
multisite 65.89% <78.37%> (+0.03%) ⬆️
single 38.61% <77.02%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ShyamGadde ShyamGadde removed [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only labels Jan 16, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 24, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: westonruter <[email protected]>
Co-authored-by: felixarntz <[email protected]>
Co-authored-by: swissspidy <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Looking mostly good! Just some minor feedback.

* @since 1.8.0
*
* @param bool $use_output_buffer Whether to use an output buffer.
* @param bool $enabled Whether to use an output buffer.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch.

}

if ( empty( $option_name ) ) {
if ( '' === $option_name ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If someone passed an option_name of '0' then this will pass through the condition since empty( '0' ) === true: https://3v4l.org/LurUe

I don't think this is a problem here though 😄

}

if ( empty( $image['file'] ) ) {
if ( ! isset( $image['file'] ) ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technically:

Suggested change
if ( ! isset( $image['file'] ) ) {
if ( ! isset( $image['file'] ) || '' === $image['file'] ) {

However, in practice it seems that if $image is not a WP_Error then really the file should always be set. So this entire if statement seems it might be worth removing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the check in 375a1ed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it might be safer to leave the check in because of the image_make_intermediate_size filter applied to the file key. Let me know if you feel strongly about removing it!

Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@ShyamGadde This looks good, thank you for working on this! Just a few small notes on potential improvements.

Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @ShyamGadde, this basically looks good to me.

Two more things that I missed in the review before. Would be great if you could address them, but I will preemptively approve.

Copy link
Copy Markdown
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Just a nit suggestion left, but pre-approving!

@westonruter westonruter merged commit 10f4dc0 into WordPress:trunk Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no milestone PRs that do not have a defined milestone for release [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add checks to disallow use of empty()

3 participants