Skip to content

Commit 5309879

Browse files
committed
ReferencedNameHelper: methods returning reference should not be considered as a referenced name
1 parent 604f322 commit 5309879

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ private static function isReferencedName(\PHP_CodeSniffer\Files\File $phpcsFile,
196196
return false;
197197
} elseif ($previousToken['code'] === T_COMMA && TokenHelper::findPreviousLocal($phpcsFile, [T_CONST], $previousPointer - 1) !== null) {
198198
return false;
199+
} elseif ($previousToken['code'] === T_BITWISE_AND && TokenHelper::findPreviousLocal($phpcsFile, [T_FUNCTION], $previousPointer - 1) !== null) {
200+
return false;
199201
}
200202

201203
$isProbablyReferencedName = !in_array(

tests/Helpers/ReferencedNameHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,13 @@ public function testConstantIsNotReferencedName(): void
137137
$this->assertCount(0, $names);
138138
}
139139

140+
public function testMethodReturningReferenceIsNotReferencedName(): void
141+
{
142+
$codeSnifferFile = $this->getCodeSnifferFile(
143+
__DIR__ . '/data/methodReturnsReference.php'
144+
);
145+
$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
146+
$this->assertCount(0, $names);
147+
}
148+
140149
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
6+
public function & foo()
7+
{
8+
}
9+
10+
}

0 commit comments

Comments
 (0)