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

Style sanitizer contains a piece of logic that doesn't seem to have any effect #3232

Closed
schlessera opened this issue Sep 12, 2019 · 5 comments · Fixed by #3235
Closed

Style sanitizer contains a piece of logic that doesn't seem to have any effect #3232

schlessera opened this issue Sep 12, 2019 · 5 comments · Fixed by #3235
Assignees
Labels
Milestone

Comments

@schlessera
Copy link
Collaborator

The style sanitizer contains piece of logic that stores "$indices_by_stylesheet_element_id". However, the entire array is only assembled, but never used.

// Keep track of the element IDs for the stylesheets.
if ( $pending_stylesheet['node'] instanceof DOMElement && $pending_stylesheet['node']->hasAttribute( 'id' ) ) {
$indices_by_stylesheet_element_id[ $pending_stylesheet['node']->getAttribute( 'id' ) ] = $pending_stylesheet_index;
}

This entire snippet could just be removed, to save processing time and memory.

@schlessera
Copy link
Collaborator Author

Note: the initialization of the array needs to be removed as well:

$indices_by_stylesheet_element_id = [];

@westonruter
Copy link
Member

Good catch. This code should have been removed with #3187.

It used to be used here, being introduced in #2346:

$included_count -= $this->exclude_all_admin_bar_css_if_excessive( $indices_by_stylesheet_element_id );
return $included_count;
}
/**
* If the admin-bar CSS was excluded, make sure the admin-bar inline CSS is also excluded, and vice-versa.
*
* @param int[] $indices_by_stylesheet_element_id Lookup of stylesheet indices by stylesheet element ID.
* @return int Number of excluded styles.
*/
private function exclude_all_admin_bar_css_if_excessive( $indices_by_stylesheet_element_id ) {
$excluded_count = 0;
$admin_bar_style_element_ids = [ 'admin-bar-css', 'admin-bar-inline-css' ];
$should_exclude_admin_bar_inline_css = false;
foreach ( $admin_bar_style_element_ids as $admin_bar_style_element_id ) {
if ( ! isset( $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] ) ) {
continue;
}
if ( false === $this->pending_stylesheets[ $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] ]['included'] ) {
$should_exclude_admin_bar_inline_css = true;
break;
}
}
if ( $should_exclude_admin_bar_inline_css ) {
foreach ( $admin_bar_style_element_ids as $admin_bar_style_element_id ) {
$needs_exclusion = (
isset( $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] )
&&
true === $this->pending_stylesheets[ $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] ]['included']
);
if ( $needs_exclusion ) {
$this->pending_stylesheets[ $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] ]['included'] = false;
$excluded_count++;
}
}
}
return $excluded_count;

@westonruter
Copy link
Member

Curious: How did you find this logic was not being used?

@schlessera
Copy link
Collaborator Author

@westonruter PHPStorm actually shows this (at least with my current settings):

Image 2019-09-17 at 6 49 24 PM

You can see that the code is grayed out, which means it is not being used. When you hover over it with the mouse, you'll get additional information.

@schlessera
Copy link
Collaborator Author

schlessera commented Sep 17, 2019

Oh, I just noticed that this actually comes from a paid addon to PHPStorm: https://kalessil.github.io/php-inspections-ultimate.html

Image 2019-09-17 at 7 02 54 PM

I can heartily recommend this plugin, and @kalessil is extremely responsive if you hit issues or have ideas for additional checks.

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

Successfully merging a pull request may close this issue.

2 participants