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

Eliminate usage of empty() construct #1803

Merged
merged 18 commits into from
Jan 28, 2025

Conversation

ShyamGadde
Copy link
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
Copy link

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
Copy link

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
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.

@@ -220,7 +220,7 @@ public function use_output_buffer(): bool {
*
* @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
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
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 😄

@@ -185,7 +185,7 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri
return $image;
}

if ( empty( $image['file'] ) ) {
if ( ! isset( $image['file'] ) ) {
Copy link
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
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
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!

plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
Copy link
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.

plugins/dominant-color-images/hooks.php Show resolved Hide resolved
plugins/webp-uploads/helper.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
Copy link
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.

plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
plugins/webp-uploads/hooks.php Outdated Show resolved Hide resolved
Copy link
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
15 checks passed
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