WPDBTrait::is_wpdb_method_call(): fix false positives for static method calls to non-global classes called wpdb#2753
Merged
Conversation
dingo-d
approved these changes
Jul 8, 2026
jrfnl
approved these changes
Jul 8, 2026
jrfnl
left a comment
Member
There was a problem hiding this comment.
LGTM. Thanks @rodrigoprimo. I left one nitpick comment, but not a blocker.
1e8eb9a to
c0c3e9d
Compare
Contributor
Author
|
Thanks for your review, @jrfnl! I have applied your suggestion. |
…od calls to non-global classes called wpdb The `DB/PreparedSQL` and `DB/PreparedSQLPlaceholders` sniffs were producing false positives for static method calls to a class named `wpdb` that is preceded by a namespace. The root cause was in `WPDBTrait::is_wpdb_method_call()`, which did not check whether the `wpdb` token was namespaced before treating it as a call to the global `wpdb` class. The fix makes the method return `false` when the `wpdb` token is a namespaced call to a non-global `wpdb` class. Fixes 2710
c0c3e9d to
e1e2260
Compare
Member
|
Thanks @rodrigoprimo I've squashed the third commit into the second now and will merge once the build has passed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
WordPress.DB.PreparedSQLandWordPress.DB.PreparedSQLPlaceholderssniffs were producing false positives for static method calls to a class namedwpdbthat is preceded by a namespace (e.g.MyNamespace\wpdb::prepare()). The root cause was inWPDBTrait::is_wpdb_method_call(), which did not check whether thewpdbtoken was namespaced before treating it as a call to the globalwpdbclass.The fix makes the method return
falsewhen thewpdbtoken is a namespaced call to a non-globalwpdbclass, so these calls are no longer mistaken for the globalwpdbobject.Suggested changelog entry
WordPress.DB.PreparedSQLandWordPress.DB.PreparedSQLPlaceholders: fixed a false positive for static method calls to a non-global class namedwpdb.Related issues/external references
Fixes #2710