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 #43233

Merged
merged 3 commits into from Feb 22, 2024
Merged

Apply Rector suggestions for PHP 8.1 #43233

merged 3 commits into from Feb 22, 2024

Conversation

asumaran
Copy link
Contributor

@asumaran asumaran commented Jan 3, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Subset of WPCOM changes for PHP 8.1 compatibility based on the D128575-code diff.

Ref: p7H4VZ-4x1-p2

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.

In any case, I wanted to provide some basic testing steps in case we want to test some file changes:

  • plugins/woocommerce/src/Admin/API/OnboardingTasks.php
    • Go to wp-admin/admin.php?page=wc-admin&task=products
    • Click Grouped product.
    • You should be able to see guided tour.
  • plugins/woocommerce/src/Admin/API/Plugins.php
    • No need to test this one. It just initialized a variable with a default value.
    • Also, I haven’t found a way to test this one. Seems related to Square.
  • plugins/woocommerce/src/Admin/API/Reports/Categories/DataStore.php
    • This one doesn't need testing. The return type just got updated in the docblock. There's no code change.
  • plugins/woocommerce/src/Admin/API/Reports/Coupons/Stats/Segmenter.php
    • Didn’t find a way to test this but testing Coupon stats should be enough.
    • Go to Analytics > Coupons. Charts should be visible.
  • plugins/woocommerce/src/Admin/API/Reports/Orders/Stats/Segmenter.php
    • Didn’t find a way to test this but testing Orders stats should be enough.
    • Go to Analytics > Orders. Charts should be visible.
  • plugins/woocommerce/src/Admin/API/Reports/Products/Stats/Segmenter.php
    • Didn’t find a way to test this but testing Products stats should be enough.
    • Go to Analytics > Products. Charts should be visible.
  • plugins/woocommerce/src/Admin/API/Reports/Segmenter.php
    • Didn’t find a way to test this but checking any Analytics page should be enough. the code doesn’t do anything harmful. just adds a type check before count
  • plugins/woocommerce/src/Admin/API/Reports/Taxes/DataStore.php
    plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/DataStore.php
    • Create a couple tax rates, apply a different country code for each one.
    • Create two orders one for each tax rate.
    • Go to Analytics > Taxes. It should show orders correctly.
  • plugins/woocommerce/src/Admin/API/Reports/TimeInterval.php
    • Didn’t find a way to test this. Code only adds a type check. In any case unit tests should cover it.
  • plugins/woocommerce/src/Admin/API/Reports/Variations/Stats/Segmenter.php
    • Doesn't need testing. The return type just got updated in the docblock and just initializes a variable with a default value.
  • plugins/woocommerce/src/Admin/API/Themes.php
    • No need to test this one as it just fixes how the variable is initialized.
    • In any case visiting any WooCommerce page should confirm it works since the code is run on every page to register the wc-admin/themes REST route.
  • plugins/woocommerce/src/Admin/PageController.php
    • Visit any WooCommerce page. The page title should be correct.
  • plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginsActivatedRuleProcessor.php
    • No need to test this as it only added a type check before count
  • plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php
    • No need to test this as it only added a type check before count
  • plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php
    • No need to test this as it only added a type check before count

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

Comment

@asumaran asumaran self-assigned this Jan 3, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jan 3, 2024
Copy link
Contributor

github-actions bot commented Jan 3, 2024

Test Results Summary

Commit SHA: 15641d1

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests316002803447m 26s

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.

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.

@asumaran asumaran marked this pull request as ready for review January 12, 2024 22:54
@asumaran asumaran requested review from a team and coreymckrill and removed request for a team January 17, 2024 21:46
Copy link
Contributor

Hi @coreymckrill,

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

@@ -192,7 +192,7 @@ public function get_item_schema() {
* @return array
*/
public function get_collection_params() {
$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
$params = [ 'context' => $this->get_context_param( array( 'default' => 'view' ) ) ];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$params = [ 'context' => $this->get_context_param( array( 'default' => 'view' ) ) ];
$params = array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ) );

In WP code style rules, the longform array syntax is preferred to the shorter []. In this case, I think it also makes it easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coreymckrill I've fixed all PHP Lint issues 2355e20

@asumaran asumaran marked this pull request as ready for review February 21, 2024 22:28
Copy link
Collaborator

@coreymckrill coreymckrill left a comment

Choose a reason for hiding this comment

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

👍 Looks good! Thanks @asumaran

@coreymckrill coreymckrill merged commit f4bccaa into trunk Feb 22, 2024
38 checks passed
@coreymckrill coreymckrill deleted the as-diff-D128575 branch February 22, 2024 23:37
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 22, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 22, 2024
@nigeljamesstevenson nigeljamesstevenson added needs: internal testing Indicates if the PR requires further testing conducted by Solaris 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 23, 2024
Konamiman pushed a commit that referenced this pull request Mar 13, 2024
* PHP8 fixes for src/Admin

* Add changelog entry

* Fix PHP Lint issues
@@ -165,7 +165,7 @@ protected function get_segments( $type, $query_params, $table_name ) {

$segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table );
} elseif ( 'variation' === $this->query_args['segmentby'] ) {
if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) {
if ( ! isset( $this->query_args['product_includes'] ) || ! is_array( count( $this->query_args['product_includes'] ) ) || count( $this->query_args['product_includes'] ) !== 1 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@asumaran it appears this change actually broke our Analytics view when comparing variation products within Analytics > Products and then selecting a variable product.
I assume this wasn't suppose to be wrapped in a count method?

Copy link
Contributor

Choose a reason for hiding this comment

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

I created a PR with a fix: #45939

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@louwie17 I'll give a look at the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris 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

5 participants