Skip to content

Commit 6e68589

Browse files
authored
Merge pull request #160 from PHPCSStandards/feature/sync-with-upstream-bcfile-isreference
BCFile::isReference(): sync with upstream
2 parents b97413b + 0b8265e commit 6e68589

File tree

7 files changed

+12
-11
lines changed

7 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Notes:
2727
* New [`PHPCSUtils\Utils\UseStatements::splitAndMergeImportUseStatement()`](https://phpcsutils.com/phpdoc/classes/PHPCSUtils-Utils-UseStatements.html#method_splitAndMergeImportUseStatement) method. [#117](https://github.com/PHPCSStandards/PHPCSUtils/pull/117)
2828

2929
#### PHPCS Backcompat
30-
* `BCFile::getMethodProperties()`: support for "static" as a return type (PHP 8). [#134](https://github.com/PHPCSStandards/PHPCSUtils/pull/134)
30+
* `BCFile::getMethodProperties()`: support for "static" as a return type (PHP 8). [#134](https://github.com/PHPCSStandards/PHPCSUtils/pull/134) [PHPCS#2952](https://github.com/squizlabs/PHP_CodeSniffer/pull/2952)
3131

3232
#### TestUtils
3333
* [`UtilityMethodTestCase`]: new public `$phpcsVersion` property for use in tests. [#107](https://github.com/PHPCSStandards/PHPCSUtils/pull/107)
@@ -99,6 +99,7 @@ Notes:
9999

100100
#### PHPCS Backcompat
101101
* `BCFile::findEndOfStatement()`: now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. [#143](https://github.com/PHPCSStandards/PHPCSUtils/pull/143)
102+
* `BcFile::isReference()`: bug fix, the reference operator was not recognized as such for closures declared to return by reference. [#160](https://github.com/PHPCSStandards/PHPCSUtils/pull/160) [PHPCS#2977](https://github.com/squizlabs/PHP_CodeSniffer/pull/2977)
102103

103104
#### Utils
104105
* `FunctionDeclarations::getArrowFunctionOpenClose()`: now supports arrow functions when used as a function argument, in line with the same change made in PHPCS 3.5.5. [#143](https://github.com/PHPCSStandards/PHPCSUtils/pull/143)

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
976976
* - References to class properties with `self::`, `parent::`, `static::`,
977977
* `namespace\ClassName::`, `classname::` were not recognized as references.
978978
* - PHPCS 3.5.3: Added support for PHP 7.4 `T_FN` arrow functions returning by reference.
979+
* - PHPCS 3.5.6: Bug fix: the reference operator for closures declared to return by reference was
980+
* not recognized as a reference. PHPCS#2977.
979981
*
980982
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
981983
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
@@ -1000,6 +1002,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
10001002
$tokenBefore = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
10011003

10021004
if ($tokens[$tokenBefore]['code'] === T_FUNCTION
1005+
|| $tokens[$tokenBefore]['code'] === T_CLOSURE
10031006
|| FunctionDeclarations::isArrowFunction($phpcsFile, $tokenBefore) === true
10041007
) {
10051008
// Function returns a reference.

PHPCSUtils/Utils/Operators.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class Operators
5959
* Determine if the passed token is a reference operator.
6060
*
6161
* Main differences with the PHPCS version:
62-
* - Bug fixed: the reference operator for closures declared to return by reference was not
63-
* recognized as a reference.
64-
* {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/2977 Open PR upstream}
6562
* - Defensive coding against incorrect calls to this method.
6663
* - Improved handling of select tokenizer errors involving short lists/short arrays.
6764
*

Tests/BackCompat/BCFile/IsReferenceTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,6 @@ $closure = function() use (&$var){};
165165

166166
/* testArrowFunctionReturnByReference */
167167
fn&($x) => $x;
168+
169+
/* testClosureReturnByReference */
170+
$closure = function &($param) use ($value) {};

Tests/BackCompat/BCFile/IsReferenceTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ public function dataIsReference()
312312
'/* testArrowFunctionReturnByReference */',
313313
true,
314314
],
315+
[
316+
'/* testClosureReturnByReference */',
317+
true,
318+
],
315319
];
316320
}
317321
}

Tests/Utils/Operators/IsReferenceDiffTest.inc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ if ($foo) {}
1111
/* testTokenizerIssue1284PHPCSlt280C */
1212
if ($foo) {}
1313
[&$a, $b];
14-
15-
/* testClosureReturnByReference */
16-
$closure = function &($param) use ($value) {};

Tests/Utils/Operators/IsReferenceDiffTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ public function dataIsReference()
8585
'/* testTokenizerIssue1284PHPCSlt280C */',
8686
true,
8787
],
88-
'closure-return-by-reference' => [
89-
'/* testClosureReturnByReference */',
90-
true,
91-
],
9288
];
9389
}
9490
}

0 commit comments

Comments
 (0)