WPDBTrait
Helper utilities for sniffs which examine WPDB method calls.
Tags
Table of Contents
Methods
- is_wpdb_method_call() : bool
- Checks whether this is a call to one of a specific group of $wpdb method(s).
Methods
is_wpdb_method_call()
Checks whether this is a call to one of a specific group of $wpdb method(s).
protected
final is_wpdb_method_call(File $phpcsFile, int $stackPtr, array<string|int, mixed> $target_methods) : bool
Supports both instance method calls (e.g., $wpdb->prepare()) and static
method calls (e.g., wpdb::esc_like()).
Note: Static calls on non-static wpdb methods are problematic at runtime, but this helper still matches them so sniffs can flag them in the code under scan.
If the following properties are explicitly declared in the class using this trait, they will be automatically set:
$methodPtr: Stack pointer to the method name.$i: Stack pointer to the opening parenthesis of the method call.$end: Stack pointer to the comma after the first parameter, or to the token directly after the first parameter if there is no comma.
The $methodPtr and $i properties may be set even when this method returns false
(e.g., for property access like $wpdb->show_errors).
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The index of the $wpdb variable or wpdb (class) name token.
- $target_methods : array<string|int, mixed>
-
Array of methods. Key(s) should be method name in lowercase.
Tags
Return values
bool —Whether this is a $wpdb method call.