Skip to content

Commit 27eaaaa

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForStaticMember(): fix comment tolerance [2] (#148)
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 fef613a commit 27eaaaa

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ protected function checkForStaticMember(File $phpcsFile, $stackPtr, $varName, $c
685685
}
686686
// "When calling static methods, the function call is stronger than the
687687
// static property operator" so look for a function call.
688-
$parenPointer = $phpcsFile->findNext([T_OPEN_PARENTHESIS], $stackPtr, $stackPtr + 2);
689-
if ($parenPointer) {
688+
$parenPointer = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
689+
if ($parenPointer !== false && $tokens[$parenPointer]['code'] === T_OPEN_PARENTHESIS) {
690690
return false;
691691
}
692692
return true;

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithVariableCallFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function funcUsingSelfCallbackFromAlias($meta, $callback) {
77
}
88

99
public function funcUsingSelfCallbackFromArgument($meta, $callback) {
10-
return self::$callback( $meta );
10+
return self::$callback /*comment*/ ( $meta );
1111
}
1212

1313
public function funcUsingStaticCallbackFromArgument($meta, $callback) {

0 commit comments

Comments
 (0)