Skip to content

Commit 1237ca4

Browse files
authored
Helper::findPreviousFunctionPtr(): fix comment tolerance (#137)
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 d664484 commit 1237ca4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ public static function findPreviousFunctionPtr(File $phpcsFile, $openPtr) {
140140
// so we look backwards from the opening bracket for the first thing that
141141
// isn't a function name, reference sigil or whitespace and check if it's a
142142
// function keyword.
143-
$functionPtrTypes = [T_STRING, T_WHITESPACE, T_BITWISE_AND];
143+
$functionPtrTypes = Tokens::$emptyTokens;
144+
$functionPtrTypes[T_STRING] = T_STRING;
145+
$functionPtrTypes[T_BITWISE_AND] = T_BITWISE_AND;
146+
144147
return self::getIntOrNull($phpcsFile->findPrevious($functionPtrTypes, $openPtr - 1, null, true, null, true));
145148
}
146149

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
function &function_with_return_by_reference_and_param($param) {
2+
function /*comment*/ &function_with_return_by_reference_and_param($param) {
33
echo $param;
44
return $param;
55
}

0 commit comments

Comments
 (0)