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

Apply Rector suggestions for PHP 8.1 #41482

Merged
merged 33 commits into from Feb 1, 2024
Merged

Conversation

asumaran
Copy link
Contributor

@asumaran asumaran commented Nov 15, 2023

Changes proposed in this Pull Request:

Applied suggestions based on Rector's static analysis for PHP 8.1.

This is a continuation of #41253 and #40801

Ref: D128845-code

How to test the changes in this Pull Request:

The changes on this PR are based on changes currently made in WPCOM, As there are no logic changes, only compatibility with PHP 8.1, it was deemed unnecessary to include testing instructions. To put it simply, the current tests should be able to complete without any problems, and that should be sufficient.

Anyway, here's some testing instructions:

plugins/woocommerce/includes/class-wc-product-factory.php

  • Creating a product should be done without issues.
  • I didn’t found a way to test the backwards compatibility case but forced it via code and it worked fine.

plugins/woocommerce/includes/class-wc-query.php

  • Go to WooCommerce > Settings. Then enable “Enable tax rates and calculations”
  • Visit the shop page. http://site.tld/shop/ products should display correct prices without issues.

plugins/woocommerce/includes/class-wc-tracker.php

  • No need to test this as unit tests (pnpm test:php:env --filter=WC_Tracker_Test) takes care of it.

plugins/woocommerce/includes/emails/class-wc-email-new-order.php

  • Create an order and make sure to receive a “new order” email or any order related email.

plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php

  • Should be able to enable “Cash on delivery” payment method and make an order without issues.

plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php

  • Since the changes are straightforward, we don't need to test this one. To double check I’ve installed the PayPal extension and made sure ordering and refunding works fine.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Apply Rector suggestions for PHP 8.1

Comment

@asumaran asumaran added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Nov 15, 2023
@asumaran asumaran self-assigned this Nov 15, 2023
Copy link
Contributor

github-actions bot commented Nov 15, 2023

Hi @jorgeatorres,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@asumaran asumaran marked this pull request as ready for review November 15, 2023 23:02
Copy link
Contributor

github-actions bot commented Nov 15, 2023

Test Results Summary

Commit SHA: ad4e25c

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests295001403096m 31s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@asumaran
Copy link
Contributor Author

@prettyboymp I've removed a few false positives. Those are explained on every commit just in case you want to double check.

Copy link
Contributor

@prettyboymp prettyboymp left a comment

Choose a reason for hiding this comment

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

Changes look good overall. We can remove the ones that aren't needed since we know the code should already return the expected data types.

@prettyboymp
Copy link
Contributor

Changes look good. May need to change the changelog entry though.

@asumaran asumaran force-pushed the as-update-to-php-81-2 branch 2 times, most recently from 73ef850 to 64ed233 Compare January 17, 2024 22:44
@asumaran asumaran requested review from a team and jorgeatorres and removed request for a team January 17, 2024 22:56
Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

@asumaran: This looks good to me. Left some feedback about using static vs self but I'm pre-approving for now.

plugins/woocommerce/includes/class-wc-product-factory.php Outdated Show resolved Hide resolved
@asumaran asumaran marked this pull request as draft January 23, 2024 18:27
@asumaran asumaran marked this pull request as ready for review January 26, 2024 20:08
@asumaran
Copy link
Contributor Author

@jorgeatorres can we merge this one?

asumaran and others added 10 commits January 30, 2024 17:46
$missing_tables will always be an array
Rector issue: AddDefaultValueForUndefinedVariableRector.

This time the early return is valid so there’s no need to move the $process_limit assignment to the top.
$orders is used as an array lines below. Add `is_array` just in case the “paginate” param is used which would change $orders to an object.
Simplifies variable check given that they are used as an array lines below.
In the previous loop the $data variable is being built as an array of arrays. Then $value in this loop will allways be array.
get_children’s method. of a WC_Product instance will always return an array.
Ask if varialbe is array since it only can be array or false.
@jorgeatorres
Copy link
Member

@jorgeatorres can we merge this one?

It looks good to me, but I see that @prettyboymp hasn't approved yet.

@asumaran
Copy link
Contributor Author

@jorgeatorres it's approved now and all tests passed. should be good to merge 👍

@jorgeatorres jorgeatorres merged commit 9bb7cd7 into trunk Feb 1, 2024
35 checks passed
@jorgeatorres jorgeatorres deleted the as-update-to-php-81-2 branch February 1, 2024 10:06
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 1, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 1, 2024
@nigeljamesstevenson nigeljamesstevenson added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 1, 2024
thealexandrelara pushed a commit that referenced this pull request Feb 1, 2024
* Apply Rector suggestions

* Add changefile(s) from automation for the following project(s): woocommerce

* Restore false positive

$missing_tables will always be an array

* Restore false positive.

Rector issue: AddDefaultValueForUndefinedVariableRector.

This time the early return is valid so there’s no need to move the $process_limit assignment to the top.

* Ask if $orders is an array

$orders is used as an array lines below. Add `is_array` just in case the “paginate” param is used which would change $orders to an object.

* Check if variable is array

Simplifies variable check given that they are used as an array lines below.

* Restore code as taxes is always an array

* Restore false positive

In the previous loop the $data variable is being built as an array of arrays. Then $value in this loop will allways be array.

* Restore false positive

get_children’s method. of a WC_Product instance will always return an array.

* Simplify variable check

Ask if varialbe is array since it only can be array or false.

* Restore false positive

WC_Blocks_Utils::get_blocks_from_page() will always return an array.

* Restore false positive

There’s a check asking if $existing_meta_data[ $meta_data->key ] is array.

* Restore false positive

$child_ids will always be an array.

* Restore false positives

WC_Product->get_visible_children() will always return an array.

* Restore false positives

WC_Product->get_children() will always return an array.

* Restore false positive

WC_Product->get_visible_children() will always return an array.

* Restore false positive

WC_Order->get_items() will always return an array.

* Restore false positive

The get_matching_rates private method will always return an array.

Updated the @return declaration to be an array instead of boolean.

* Remove unnecessary array type casting.

* Restore false positive

$this->get_children() will always return an array.

* Fix lint issues

* Remove unnecessary default assignment

* Remove unnecessary is_array check

* Remove unnecessary is_array check

* Remove unnecessary is_array check

* Change default value from null to false

* Remove unnecessary is_array check

* Update changelog entry

* Update changelog entry

* Update changelog entry

* Add changefile(s) from automation for the following project(s): woocommerce

* Update changelog entry

* Use self for consistency

---------

Co-authored-by: github-actions <github-actions@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants