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

Use static closures for minor performance improvement whenever instance access is not needed #729

Merged
merged 8 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function perflab_load_modules_page( $modules = null, $focus_areas = null ) {
add_settings_field(
$module_slug,
$module_data['name'],
function() use ( $module_slug, $module_data, $module_settings ) {
static function() use ( $module_slug, $module_data, $module_settings ) {
perflab_render_modules_page_field( $module_slug, $module_data, $module_settings );
},
PERFLAB_MODULES_SCREEN,
Expand Down Expand Up @@ -329,7 +329,7 @@ function perflab_get_modules( $modules_root = null ) {

uasort(
$modules,
function( $a, $b ) {
static function( $a, $b ) {
return strnatcasecmp( $a['name'], $b['name'] );
}
);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^4|^5|^6|^7|^8|^9",
"slevomat/coding-standard": "^8.0",
Copy link
Member

Choose a reason for hiding this comment

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

This coding standard requires php 7.2. Will would make this plugin break in 7.2- no.

https://github.com/slevomat/coding-standard/blob/f69e2524e8770efb9b3e5ac4a0ebc0d54eb446d7/composer.json#L19

Copy link
Member

@swissspidy swissspidy May 16, 2023

Choose a reason for hiding this comment

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

It would not break the plugin, because the composer autoloader is only used in tests.

It would just break tests running on PHP 5.6. However, right now tests are not running on this version on CI, so... 🤷

Edit: looks like there is #399 for updating tests.

Copy link
Member Author

@westonruter westonruter May 16, 2023

Choose a reason for hiding this comment

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

Please continue discussion at #730 (comment)

As I understand, there are three possible ways to about this:

  1. Have a separate composer file for PHP 7.2+
  2. In GHA workflow, just-in-time composer require this package before doing composer install before running PHPCS
  3. In GHA workflow, just-in-time composer remove this package before doing composer install prior to running PHPUnit in PHP<7.2.

I think the third option is ideal, since all normal development environments would be running PHP 7.2+. It's only the exception case, specifically on GHA, where PHP 5.6 is needed. This would allow a developer to have all packages installed normally.

The first option doesn't seem ideal since there would be a separate composer file to maintain, and Dependabot wouldn't automatically be aware of it.

This comment was marked as duplicate.

Copy link
Member Author

Choose a reason for hiding this comment

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

We may not want this sniff after all. See WordPress/wordpress-develop#4457 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Noting that we could still make a separate decision from core here, there are several plugins that have stricter requirements than core to enforce better coding practices. I don't feel strongly about this one, but I feel like if we can find a way that we can integrate it that remains compatible with PHP 5.6, I'd be happy to include it.

Copy link
Member

Choose a reason for hiding this comment

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

I am not against using this rule set, but php 5.6 compat is the key here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can the 5.6 compat be handled as part of #399? Without CI actually running anything in 5.6, it makes it a bit difficult to verify the compat is working, or at least it seems a bit premature.

"squizlabs/php_codesniffer": "^3.5",
"wp-coding-standards/wpcs": "^2.2",
"wp-phpunit/wp-phpunit": "^5.8",
Expand Down
Loading