Skip to content

Commit 442f5d3

Browse files
authored
Merge pull request #131 from PHPCSStandards/feature/objectdeclarations-getname-bug-fix
ObjectDeclarations::getName(): bug fix for functions returning by reference
2 parents 3a50017 + 614972a commit 442f5d3

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

PHPCSUtils/Utils/ObjectDeclarations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static function getName(File $phpcsFile, $stackPtr)
120120
$exclude = Tokens::$emptyTokens;
121121
$exclude[] = \T_OPEN_PARENTHESIS;
122122
$exclude[] = \T_OPEN_CURLY_BRACKET;
123+
$exclude[] = \T_BITWISE_AND;
123124

124125
$nameStart = $phpcsFile->findNext($exclude, ($stackPtr + 1), $stopPoint, true);
125126
if ($nameStart === false) {

Tests/BackCompat/BCFile/GetDeclarationNameTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ $class = new class extends SomeClass {
2727
/* testFunction */
2828
function functionName() {}
2929

30+
/* testFunctionReturnByRef */
31+
function & functionNameByRef();
32+
3033
/* testClass */
3134
abstract class ClassName {
3235
/* testMethod */
3336
public function methodName() {}
3437

3538
/* testAbstractMethod */
3639
abstract protected function abstractMethodName();
40+
41+
/* testMethodReturnByRef */
42+
private function &MethodNameByRef();
3743
}
3844

3945
/* testExtendedClass */

Tests/BackCompat/BCFile/GetDeclarationNameTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public function dataGetDeclarationName()
133133
'/* testFunction */',
134134
'functionName',
135135
],
136+
'function-return-by-reference' => [
137+
'/* testFunctionReturnByRef */',
138+
'functionNameByRef',
139+
],
136140
'class' => [
137141
'/* testClass */',
138142
'ClassName',
@@ -145,6 +149,10 @@ public function dataGetDeclarationName()
145149
'/* testAbstractMethod */',
146150
'abstractMethodName',
147151
],
152+
'method-return-by-reference' => [
153+
'/* testMethodReturnByRef */',
154+
'MethodNameByRef',
155+
],
148156
'extended-class' => [
149157
'/* testExtendedClass */',
150158
'ExtendedClass',

0 commit comments

Comments
 (0)