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

Fix bug in WordPress_Sniffs_VIP_DirectDatabaseQuerySniff #786

Merged
merged 1 commit into from
Jan 16, 2017

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 15, 2017

The WordPress.VIP.DirectDatabaseQuery sniff allows for adding custom database query caching functions to the predefined lists of known WP core database query caching functions.

The known WP core database query caching functions are contained in static variables in the WordPress_Sniff base class and are currently only used by the WordPress.VIP.DirectDatabaseQuery sniff.

Up to now, if custom functions were passed to this sniff, it would merge them with the lists of WP core functions and then overwrite the values of the static properties in the WordPress_Sniff base class.

While no other sniff is using these properties, this is not much of a problem (yet), but as soon as another sniff would start using these properties, this behaviour would have the unintended side-effect of affecting the other sniff as well. Even worse, whether this side-effect would come into play might be unpredictable as it would depend on the running order of the sniffs which can change without notice.

To fix this, I have introduced three new private properties to the WordPress.VIP.DirectDatabaseQuery sniff which will hold the merged versions of the function lists.

I've also moved the setting of these properties to a dedicated function.

Related to #614

The `WordPress.VIP.DirectDatabaseQuery` sniff allows for adding custom database query caching functions to the predefined lists of known WP core database query caching functions.

The known WP core database query caching functions are contained in static variables in the `WordPress_Sniff` base class and are currently only used by the `WordPress.VIP.DirectDatabaseQuery` sniff.

Up to now, if custom functions were passed to this sniff, it would merge them with the lists of WP core functions and then **overwrite** the values of the static properties in the `WordPress_Sniff` base class.

While no other sniff is using these properties, this is not much of a problem (yet), but as soon as another sniff would start using these properties, this behaviour would have the unintended side-effect of affecting the other sniff as well. Even worse, whether this side-effect would come into play might be unpredictable as it would depend on the running order of the sniffs which can change without notice.

To fix this, I have introduced three new private properties to the `WordPress.VIP.DirectDatabaseQuery` sniff which will hold the merged versions of the function lists.

I've also moved the setting of these properties to a dedicated function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants