-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
} | ||
|
||
// Server time. | ||
$date = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); |
There was a problem hiding this comment.
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
$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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
$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(); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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.
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.
efc18b9
to
8952731
Compare
'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'] ); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
'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. |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialized in e6f03ea
Changed: Moving $info['wp-server'] to own function
Follow up to #7027 as discussed with @dmsnell and @costdev
Summary of the coming steps:
Refactoring WP_Debug_Data::debug_data(); into smaller functions for
$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.