Skip to content

Commit be7193e

Browse files
committed
WP/CronInterval: make callback function name lookup case-insensitive
The sniff was incorrectly treating callback function names as case-sensitive when trying to locate the callback function definition. This led to false positives when the callback reference case did not match the function declaration case. The fix ensures callback names are compared case-insensitively using `strcasecmp()` when searching for function declarations in the code.
1 parent adaf62d commit be7193e

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

WordPress/Sniffs/WP/CronIntervalSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private function find_function_by_name( $functionName ) {
291291
for ( $ptr = 0; $ptr < $this->phpcsFile->numTokens; $ptr++ ) {
292292
if ( \T_FUNCTION === $this->tokens[ $ptr ]['code'] ) {
293293
$foundName = FunctionDeclarations::getName( $this->phpcsFile, $ptr );
294-
if ( $foundName === $functionName ) {
294+
if ( strcasecmp( $foundName, $functionName ) === 0 ) {
295295
$functionPtr = $ptr;
296296
break;
297297
} elseif ( isset( $this->tokens[ $ptr ]['scope_closer'] ) ) {

WordPress/Tests/WP/CronIntervalUnitTest.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ add_filter( 'cron_schedules', function ( $schedules ) {
164164
// Correctly handle fully qualified WP time constants.
165165
class FQNConstants {
166166
public function add_schedules() {
167-
add_filter( 'cron_schedules', array( $this, 'add_weekly_schedule' ) ); // Ok: > 15 min.
167+
add_filter( 'cron_schedules', array( $this, 'ADD_WEEKLY_SCHEDULE' ) ); // Ok: > 15 min.
168168
\add_filter( 'cron_schedules', array( $this, 'add_eight_minute_schedule' ) ); // Warning: 8 min.
169169
ADD_FILTER( 'cron_schedules', array( $this, 'add_hundred_minute_schedule' ) ); // Warning: time undetermined.
170170
\Add_Filter( 'cron_schedules', array( $this, 'sneaky_fake_wp_constant_schedule' ) ); // Warning: time undetermined.
@@ -284,7 +284,7 @@ class FirstClassCallables {
284284
public function add_schedules() {
285285
add_filter( 'cron_schedules', $this->cron_weekly_schedule(...) ); // Ok: > 15 min.
286286
add_filter( 'cron_schedules', $this->cron_eight_minute_schedule(...) ); // Warning: 8 min.
287-
add_filter( 'cron_schedules', self::cron_weekly_schedule(...) ); // Ok: > 15 min.
287+
add_filter( 'cron_schedules', self::Cron_Weekly_Schedule(...) ); // Ok: > 15 min.
288288
add_filter( 'cron_schedules', static::cron_eight_minute_schedule(...) ); // Warning: 8 min.
289289
add_filter( 'cron_schedules', [$this, 'cron_weekly_schedule'](...) ); // Ok: > 15 min.
290290
add_filter( 'cron_schedules', array($this, 'cron_eight_minute_schedule')(...) ); // Warning: 8 min.
@@ -328,6 +328,7 @@ function first_class_six_min_schedule( $schedules ) {
328328
add_filter( 'cron_schedules', first_class_six_min_schedule(...)); // Warning: 6 min.
329329
add_filter( 'cron_schedules', 'first_class_six_min_schedule'(...)); // Warning: 6 min.
330330
add_filter( 'cron_schedules', \first_class_six_min_schedule(...)); // Warning: 6 min.
331+
add_filter( 'cron_schedules', \FIRST_CLASS_SIX_MIN_SCHEDULE(...)); // Warning: 6 min.
331332
add_filter( 'cron_schedules', namespace\first_class_six_min_schedule(...)); // Warning: 6 min.
332333

333334
/*

WordPress/Tests/WP/CronIntervalUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ public function getWarningList() {
6969
329 => 1,
7070
330 => 1,
7171
331 => 1,
72-
351 => 1,
72+
332 => 1,
7373
352 => 1,
7474
353 => 1,
75+
354 => 1,
7576
);
7677
}
7778
}

0 commit comments

Comments
 (0)