Skip to content

Commit

Permalink
ReferencedNameHelper: methods returning reference should not be consi…
Browse files Browse the repository at this point in the history
…dered as a referenced name
  • Loading branch information
kukulich committed Jan 8, 2018
1 parent 604f322 commit 5309879
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions SlevomatCodingStandard/Helpers/ReferencedNameHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ private static function isReferencedName(\PHP_CodeSniffer\Files\File $phpcsFile,
return false;
} elseif ($previousToken['code'] === T_COMMA && TokenHelper::findPreviousLocal($phpcsFile, [T_CONST], $previousPointer - 1) !== null) {
return false;
} elseif ($previousToken['code'] === T_BITWISE_AND && TokenHelper::findPreviousLocal($phpcsFile, [T_FUNCTION], $previousPointer - 1) !== null) {
return false;
}

$isProbablyReferencedName = !in_array(
Expand Down
9 changes: 9 additions & 0 deletions tests/Helpers/ReferencedNameHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,13 @@ public function testConstantIsNotReferencedName(): void
$this->assertCount(0, $names);
}

public function testMethodReturningReferenceIsNotReferencedName(): void
{
$codeSnifferFile = $this->getCodeSnifferFile(
__DIR__ . '/data/methodReturnsReference.php'
);
$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
$this->assertCount(0, $names);
}

}
10 changes: 10 additions & 0 deletions tests/Helpers/data/methodReturnsReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Foo
{

public function & foo()
{
}

}

0 comments on commit 5309879

Please sign in to comment.