Skip to content

Commit 46b25ba

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForSymbolicObjectProperty(): fix comment tolerance (#154)
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 75c57a7 commit 46b25ba

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ protected function checkForSymbolicObjectProperty(File $phpcsFile, $stackPtr, $v
11001100

11011101
// Are we a symbolic object property/function derefeference?
11021102
// Search backwards for first token that isn't whitespace, is it a "->" operator?
1103-
$objectOperatorPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true);
1103+
$objectOperatorPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true, null, true);
11041104
if (($objectOperatorPtr === false) || ($tokens[$objectOperatorPtr]['code'] !== T_OBJECT_OPERATOR)) {
11051105
return false;
11061106
}

VariableAnalysis/Tests/CodeAnalysis/fixtures/ClassReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function method_with_symbolic_ref_property() {
88
$this->$property = 'some value';
99
$this -> $property = 'some value';
1010
$this->$undefined_property = 'some value';
11-
$this -> $undefined_property = 'some value';
11+
$this -> /* comment*/ $undefined_property = 'some value';
1212
$this->$ignored_property = 'some value';
1313
$this -> $ignored_property = 'some value';
1414
}

0 commit comments

Comments
 (0)