Skip to content

Commit d664484

Browse files
authored
Helper::findParenthesisOwner(): fix comment tolerance (#136)
PHP ignores comments in unexpected/unconventional places and so should the sniff. Includes adjusting an existing unit test. Without the fix, the adjusted unit test would cause test failures.
1 parent 6a4d03c commit d664484

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function findContainingOpeningBracket(File $phpcsFile, $stackPtr)
7373
* @return ?int
7474
*/
7575
public static function findParenthesisOwner(File $phpcsFile, $stackPtr) {
76-
return self::getIntOrNull($phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true));
76+
return self::getIntOrNull($phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true));
7777
}
7878

7979
/**

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithForeachFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function function_with_defined_foreach() {
4545
echo "$key2 => $value2\n";
4646
}
4747
echo "$key2 => $value2\n";
48-
foreach ($array as $element3) {
48+
foreach /*comment*/ ($array as $element3) {
4949
}
5050
foreach ($array as &$element4) {
5151
}

0 commit comments

Comments
 (0)