Skip to content

Commit 6dfd8f1

Browse files
authored
WPDBTrait::is_wpdb_method_call(): improve docblock description (#2719)
- Clarified that the method supports static method calls as well. - Replaced incomplete description with a list of the three properties that may be automatically set: `$methodPtr`, `$i`, and `$end`. - Added clarification that `$methodPtr` and `$i` may be set even when the method returns false (e.g., for property access like `$wpdb->show_errors`). - Updated `$stackPtr` parameter description to mention it can be a "wpdb class name token" as well. - Made the `$end` description more precise: it points to the comma after the first parameter, or to one past the last token of the first parameter if there is no comma.
1 parent 22d4758 commit 6dfd8f1

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

WordPress/Helpers/WPDBTrait.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@
2323
trait WPDBTrait {
2424

2525
/**
26-
* Checks whether this is a call to a $wpdb method that we want to sniff.
26+
* Checks whether this is a call to one of a specific group of $wpdb method(s).
2727
*
28-
* If available in the class using this trait, the $methodPtr, $i and $end properties
29-
* are automatically set to correspond to the start and end of the method call.
30-
* The $i property is also set if this is not a method call but rather the
31-
* use of a $wpdb property.
28+
* Supports both instance method calls (e.g., `$wpdb->prepare()`) and static
29+
* method calls (e.g., `wpdb::esc_like()`).
30+
*
31+
* Note: Static calls on non-static wpdb methods are problematic at runtime, but this
32+
* helper still matches them so sniffs can flag them in the code under scan.
33+
*
34+
* If the following properties are explicitly declared in the class using this trait,
35+
* they will be automatically set:
36+
* - `$methodPtr`: Stack pointer to the method name.
37+
* - `$i`: Stack pointer to the opening parenthesis of the method call.
38+
* - `$end`: Stack pointer to the comma after the first parameter, or to the
39+
* token directly after the first parameter if there is no comma.
40+
*
41+
* The `$methodPtr` and `$i` properties may be set even when this method returns `false`
42+
* (e.g., for property access like `$wpdb->show_errors`).
3243
*
3344
* @since 0.8.0
3445
* @since 0.9.0 The return value is now always boolean. The $end and $i member
@@ -41,7 +52,7 @@ trait WPDBTrait {
4152
* for properties in the sniff class(es) using it.}}
4253
*
4354
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
44-
* @param int $stackPtr The index of the $wpdb variable.
55+
* @param int $stackPtr The index of the $wpdb variable or wpdb (class) name token.
4556
* @param array $target_methods Array of methods. Key(s) should be method name
4657
* in lowercase.
4758
*

0 commit comments

Comments
 (0)