-
-
Notifications
You must be signed in to change notification settings - Fork 522
DB/DirectDatabaseQuery: fix handling of namespaced calls to cache functions #2619
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
base: develop
Are you sure you want to change the base?
DB/DirectDatabaseQuery: fix handling of namespaced calls to cache functions #2619
Conversation
…ctions Before this change, the sniff was not properly differentiating between fully qualified calls to global WP cache functions and namespaced calls to non-WP functions with the same name as the WP functions. In other words, the sniff was correctly identifying `\wp_cache_get()` as a WP cache function, but it was incorrectly identifying `MyNamespace\wp_cache_get()` as a WP cache function. This commit fixes this issue.
|
Hmm... so as per #2615:
... we are ignoring method calls if they mirror the WP native functions, but now this PR will start flagging namespaced function calls which mirror the WP native functions ? That sounds very inconsistent to me. |
|
That is a good point. I'm unsure what is the best approach here. I checked other WPCS sniffs to see if they have similar behavior, and those I examined behave differently. Similar to the list of cache functions used by Do you see a reason to keep the |
|
The |
…e of WP global cache functions As discussed during the PR review, this reverts changes from the previous commit which filtered out namespaced cache function calls. After discussion, it was decided to maintain the existing behavior where namespaced cache functions like `MyNamespace\wp_cache_get()` are treated as valid custom cache implementations, consistent with how method calls like `$obj->wp_cache_get()` are handled. The tests have been updated to test the new behavior.
|
Thanks for your input, @jrfnl. I have pushed a new commit reverting the changes to the sniff code and updating the tests to safeguard against regressions for the current behavior of the sniff. Is this more or less what you had in mind? Do you prefer that I update the title and description of this PR to reflect that now it only adds |
Description
Before this change, the sniff was not properly differentiating between fully qualified calls to global WP cache functions and namespaced calls to non-WP functions with the same name as the WP functions.
In other words, the sniff was correctly identifying
\wp_cache_get()as a WP cache function, but it was incorrectly identifyingMyNamespace\wp_cache_get()as a WP cache function as well. This PR fixes this issue.Suggested changelog entry
Fixed:
WordPress.DB.DirectDatabaseQuery: handling of calls to namespaced non-global functions with the same name as WP cache functions.