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

Refactored WP_Debug_Data::debug_data() - get_wp_server() #7283

Closed
wants to merge 6 commits into from

Conversation

apermo
Copy link

@apermo apermo commented Sep 3, 2024

Changed: Moving $info['wp-server'] to own function


Follow up to #7027 as discussed with @dmsnell and @costdev

Summary of the coming steps:

  1. wp-filesystem
  2. wp-constants
  3. wp-database
  4. wp-server (we are here)
  5. wp-media
  6. wp-plugins-active & wp-plugins-inactive
  7. wp-mu-plugins
  8. wp-themes-inactive
  9. wp-parent-theme
  10. wp-active-theme
  11. wp-dropins
  12. wp-paths-sizes
  13. wp-core

Refactoring WP_Debug_Data::debug_data(); into smaller functions for

  • better maintainability
  • reduced complexity
  • preparation for future unit tests
  • improved extensibility (see trac for details)
  • added php7.2 style type hints
  • fixed an error with $parent_theme_auto_update_string showing the value from $auto_updates_string (This will be handled only in Step 9)

Trac ticket: https://core.trac.wordpress.org/ticket/61648#ticket


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Sep 3, 2024

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props apermo, dmsnell, costdev, mukesh27, kebbet.

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

Copy link

github-actions bot commented Sep 3, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

}

// Server time.
$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
Copy link
Author

Choose a reason for hiding this comment

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

@dmsnell PHPstorm warned me that this line could possibly throw an exception. Since we have a highly controlled set of parameters, I think it's safe to assume we will never get this exception.

Yet PHPstorm wanted me to add a @throws in the PHPdoc, which I ignored for the time being. But what do you suggest what we do about it?

Adding a @throws will just bubble up the problem.

How about

Suggested change
$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
try {
$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
} catch ( Exception $e ) {
// It should be impossible to reach this statement. But in case let's fail gracefully.
wp_die( $e->get_message() );
}

(Untested and written in GitHub only)

Copy link
Contributor

Choose a reason for hiding this comment

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

While not impossible (See the Europe/Kyiv change in the "Changes to zone name" section - Which changed for PHP 8.2), since we're using the UTC timezone, the chance of an Exception being thrown for this call is extremely low.

It seems to be fairly safe to consider this a tooling flag that can be ignored.

I don't have strong feelings on this though. It'll probably just come down to preference.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any notes in the documentation suggesting that UTC was ever not part of the distribution. The constant DateTimeZone::UTC hints at this, and if you ask PHP to get a timezone supported by UTC it returns the string in use here.

php > var_dump( DateTimeZone::listIdentifiers( DateTimeZone::UTC ) );
array(1) {
  [0]=>
  string(3) "UTC"
}

While sometimes the documentation is wrong, it seems unlikely here, meaning that it may not even be an extremely low chance of throwing here, but not possible.

Do we need a WPCS ignore statement here? If not then I think it's fine as-is. Regardless, as I have written in other comments - this PR is about modularizing a piece of the debug data code, and I recommend against making semantic changes otherwise until that factoring has completed.

Copy link
Author

Choose a reason for hiding this comment

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

It does not trigger WPCS, just triggers the Code analysis from PHPstorm.

So we can keep it as is.

Comment on lines 971 to 974
$info['wp-server'] = self::get_wp_server();
$info['wp-database'] = self::get_wp_database();
$info['wp-constants'] = self::get_wp_constants();
$info['wp-filesystem'] = self::get_wp_filesystem();
Copy link
Author

Choose a reason for hiding this comment

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

I reordered this, to be able to get rid of the $info['wp-database'] in lines 199-202

Actually I would like to order the function calls bellow as well. OCD is itching.

This is the correct order of the function calls, and by having them correct, we can completely replace the original $info definition which was the plan of this.
And I'd like it best if we could still swap around the function defintions of get_wp_database() in line 1391 and get_wp_constants() in line 1238 to match this order.

Your thought @dmsnell ?

Copy link
Member

Choose a reason for hiding this comment

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

After discussing in Slack, this all sounds great, and I apologize for reordering these before. The insertion order of the keys in the array determines the order they are displayed in wp-admin, and so we want to preserve the existing order.

Copy link
Member

Choose a reason for hiding this comment

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

@apermo thoughts on this? when I dug into it, I felt like something ad-hoc was missing a bigger point, so I proposed encoding the ordering as a specific semantic instead of relying on how the code is already written.

#7289

Copy link
Author

Choose a reason for hiding this comment

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

@dmsnell updated the PR.

I'll add an inline comment and tag you, you've missed one thing in #7289 that we need to cover in order to match the format for both single and multisite.

Copy link

@kebbet kebbet left a comment

Choose a reason for hiding this comment

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

Strings could be more clear, while we are editing this function as a whole.

apermo and others added 2 commits September 7, 2024 07:52
Moved wp-server to a distinct function.
Sorted function calls for wp-database
Adaptations for WordPress#7289
Added a condition to unset $info['wp-paths-sizes'] for multisites to match the original state.
@apermo apermo force-pushed the refactor-wp-debug-data/part4 branch from efc18b9 to 8952731 Compare September 7, 2024 06:07
'wp-database' => self::get_wp_database(),
'wp-constants' => self::get_wp_constants(),
'wp-filesystem' => self::get_wp_filesystem(),
);

// Remove accordion for Directories and Sizes if in Multisite.
if ( $is_multisite ) {
unset( $info['wp-paths-sizes'] );
Copy link
Author

@apermo apermo Sep 7, 2024

Choose a reason for hiding this comment

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

@dmsnell See lines 167-173 and 288-348, $info['wp-paths-sizes'] shall only be visible on single sites, so I've added this unset here. I think that was why I originally opted for $info['key'] = self::get_key; instead of your approach.

And I've knowingly used is_multisite() instead of $is_multisite, we will remove $is_multisite = is_multisite();(Line 44) later in the refactoring, since it is likely only helpful in the upcoming function get_wp_core()

Copy link
Member

Choose a reason for hiding this comment

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

this seemms fine. thanks @apermo

Copy link
Member

Choose a reason for hiding this comment

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

I've updated the comment in f576b04

Copy link
Member

Choose a reason for hiding this comment

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

we could eventually filter this array and have self::get_wp_paths_sizes() return null for multi-site deployments.

Changed: replaced $is_multisite with is_multisite() as preparation for a later step.
@apermo apermo changed the title Refactored WP_Debug_Data::debug_data() Part 4 Refactored WP_Debug_Data::debug_data() - get_wp_server() Sep 7, 2024
'wp-database' => self::get_wp_database(),
'wp-constants' => self::get_wp_constants(),
'wp-filesystem' => self::get_wp_filesystem(),
);

// Remove accordion for Directories and Sizes if in Multisite.
Copy link
Member

Choose a reason for hiding this comment

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

This could probably use some rearranging. I understand that the display of the debug data in wp-admin happens to display sections in a UI like an accordion, but this function doesn't directly couple with that, does it?

Could the comment focus on the purpose of the debug data itself, and not the display?

// Path sizes are only relevant in single-site contexts.

$php_version_debug .= ' 64bit';
}

$fields['server_architecture'] = array(
Copy link
Member

Choose a reason for hiding this comment

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

we seem to be assigning keys to $fields here without initializing $fields as a variable.

Copy link
Member

Choose a reason for hiding this comment

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

initialized in e6f03ea

@dmsnell
Copy link
Member

dmsnell commented Sep 10, 2024

Merged in [59002]
19fc9c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants