Skip to content

Commit 95e3a3d

Browse files
committed
Sniff::is_in_isset_or_empty(): implement new is_in_function_call() method
This fixes potential false negatives when a method/namespaced function mirroring the name of the PHP array_key_exists() function would be used.
1 parent 7d01ff3 commit 95e3a3d

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

WordPress/Sniff.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,16 +1460,9 @@ protected function is_in_isset_or_empty( $stackPtr ) {
14601460
return true;
14611461
}
14621462

1463-
if ( \T_STRING === $previous_code && 'array_key_exists' === $this->tokens[ $previous_non_empty ]['content'] ) {
1464-
if ( $this->is_class_object_call( $previous_non_empty ) === true ) {
1465-
return false;
1466-
}
1467-
1468-
if ( $this->is_token_namespaced( $previous_non_empty ) === true ) {
1469-
return false;
1470-
}
1471-
1472-
$second_param = $this->get_function_call_parameter( $previous_non_empty, 2 );
1463+
$functionPtr = $this->is_in_function_call( $stackPtr, array( 'array_key_exists' => true ) );
1464+
if ( false !== $functionPtr ) {
1465+
$second_param = $this->get_function_call_parameter( $functionPtr, 2 );
14731466
if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) {
14741467
return true;
14751468
}

0 commit comments

Comments
 (0)