Skip to content

Commit 970a0ea

Browse files
committed
AbstractFunctionParameterSniff: fix handling of unfinished function calls
Before this commit, the `AbstractFunctionParameterSniff` class would incorrectly treat an unfinished function call (missing closing parenthesis) as a function call without parameters. This behavior is now changed and the class will bail early when the closing parenthesis is missing and assume it is a syntax error or live coding.
1 parent 02260b0 commit 970a0ea

4 files changed

Lines changed: 11 additions & 30 deletions

File tree

WordPress/AbstractFunctionParameterSniff.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,16 @@ public function is_targetted_token( $stackPtr ) {
9999
return false;
100100
}
101101

102+
if ( isset( $this->tokens[ $next ]['parenthesis_closer'] ) === false ) {
103+
// Syntax error or live coding: missing closing parenthesis.
104+
return false;
105+
}
106+
102107
// First class callable.
103108
$firstNonEmpty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true );
104-
if ( false !== $firstNonEmpty && \T_ELLIPSIS === $this->tokens[ $firstNonEmpty ]['code'] ) {
109+
if ( \T_ELLIPSIS === $this->tokens[ $firstNonEmpty ]['code'] ) {
105110
$secondNonEmpty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $firstNonEmpty + 1 ), null, true );
106-
if ( false === $secondNonEmpty || \T_CLOSE_PARENTHESIS === $this->tokens[ $secondNonEmpty ]['code'] ) {
111+
if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $secondNonEmpty ]['code'] ) {
107112
return false;
108113
}
109114
}

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.7.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* Intentional parse error (nothing after opening parenthesis).
77
* This should be the only test in this file.
88
*
9-
* Test to document that `AbstractFunctionParameterSniff::is_targetted_token()` returns true for a
10-
* function call even when there is nothing after the opening parenthesis. This test is added here
11-
* as there are no dedicated tests for the WPCS abstract classes. The WPCS abstract classes will be
12-
* replaced with PHPCSUtils similar classes in the future, so it is not worth creating dedicated
13-
* tests at this point.
9+
* Test to document that `AbstractFunctionParameterSniff::is_targetted_token()` ignores unfinished
10+
* function calls. This test is added here as there are no dedicated tests for the WPCS abstract
11+
* classes. The WPCS abstract classes will be replaced with PHPCSUtils similar classes in the
12+
* future, so it is not worth creating dedicated tests at this point.
1413
*/
1514

1615
__(

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.8.inc

Lines changed: 0 additions & 18 deletions
This file was deleted.

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ public function getWarningList( $testFile = '' ) {
195195
201 => 1,
196196
);
197197

198-
case 'I18nTextDomainFixerUnitTest.7.inc':
199-
return array(
200-
16 => 1,
201-
);
202-
203198
default:
204199
return array();
205200
}

0 commit comments

Comments
 (0)