Skip to content

Eliminate usage of empty() construct - #1803

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

westonruter merged 18 commits into
WordPress: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

Shyamsundar Gadde added 4 commits January 15, 2025 08:14
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
Signed-off-by: Shyamsundar Gadde <shyamsundar.gadde@rtcamp.com>
@ShyamGadde ShyamGadde added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Modern Image Formats Formerly WebP Uploads [slug: webp-uploads] no milestone PRs that do not have a defined milestone for release [Plugin] Image Placeholders Formerly "Dominant Color Images" [slug: dominant-color-images] [Plugin] Performance Lab [slug: performance-lab] labels Jan 16, 2025
@codecov

codecov Bot commented Jan 16, 2025 •

Copy link
Copy Markdown

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 Formerly WebP Uploads [slug: webp-uploads] [Plugin] Image Placeholders Formerly "Dominant Color Images" [slug: dominant-color-images] [Plugin] Performance Lab [slug: performance-lab] labels Jan 16, 2025
@github-actions

github-actions Bot commented Jan 24, 2025 •

Copy link
Copy Markdown

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 <shyamgadde@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>

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

@westonruter westonruter left a comment

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.

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 😄

Comment thread plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php Outdated
Comment thread plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php Outdated
Comment thread plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php Outdated
Comment thread plugins/webp-uploads/helper.php Outdated
}

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!

Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php
Comment thread plugins/webp-uploads/hooks.php Outdated
ShyamGadde and others added 4 commits January 27, 2025 18:46
Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>

@felixarntz felixarntz left a comment

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.

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

Comment thread plugins/dominant-color-images/hooks.php
Comment thread plugins/webp-uploads/helper.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php
Comment thread plugins/webp-uploads/hooks.php
Co-authored-by: Felix Arntz <flixos90@gmail.com>
ShyamGadde and others added 3 commits January 28, 2025 01:30
Co-authored-by: Felix Arntz <flixos90@gmail.com>
Co-authored-by: Felix Arntz <flixos90@gmail.com>

@felixarntz felixarntz left a comment

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.

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.

Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Co-authored-by: Felix Arntz <flixos90@gmail.com>
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated
ShyamGadde and others added 2 commits January 29, 2025 00:40
Comment thread plugins/webp-uploads/hooks.php Outdated
Comment thread plugins/webp-uploads/hooks.php Outdated

@westonruter westonruter left a comment

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.

Just a nit suggestion left, but pre-approving!

Co-authored-by: Weston Ruter <westonruter@google.com>
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