Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Notes:
* 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)

#### PHPCS Backcompat
* `BCFile::getMethodProperties()`: support for "static" as a return type (PHP 8). [#134](https://github.com/PHPCSStandards/PHPCSUtils/pull/134)
* `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)

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

#### PHPCS Backcompat
* `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)
* `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)

#### Utils
* `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)
Expand Down
3 changes: 3 additions & 0 deletions PHPCSUtils/BackCompat/BCFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
* - References to class properties with `self::`, `parent::`, `static::`,
* `namespace\ClassName::`, `classname::` were not recognized as references.
* - PHPCS 3.5.3: Added support for PHP 7.4 `T_FN` arrow functions returning by reference.
* - PHPCS 3.5.6: Bug fix: the reference operator for closures declared to return by reference was
* not recognized as a reference. PHPCS#2977.
*
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
Expand All @@ -1000,6 +1002,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
$tokenBefore = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);

if ($tokens[$tokenBefore]['code'] === T_FUNCTION
|| $tokens[$tokenBefore]['code'] === T_CLOSURE
|| FunctionDeclarations::isArrowFunction($phpcsFile, $tokenBefore) === true
) {
// Function returns a reference.
Expand Down
3 changes: 0 additions & 3 deletions PHPCSUtils/Utils/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class Operators
* Determine if the passed token is a reference operator.
*
* Main differences with the PHPCS version:
* - Bug fixed: the reference operator for closures declared to return by reference was not
* recognized as a reference.
* {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/2977 Open PR upstream}
* - Defensive coding against incorrect calls to this method.
* - Improved handling of select tokenizer errors involving short lists/short arrays.
*
Expand Down
3 changes: 3 additions & 0 deletions Tests/BackCompat/BCFile/IsReferenceTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,6 @@ $closure = function() use (&$var){};

/* testArrowFunctionReturnByReference */
fn&($x) => $x;

/* testClosureReturnByReference */
$closure = function &($param) use ($value) {};
4 changes: 4 additions & 0 deletions Tests/BackCompat/BCFile/IsReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ public function dataIsReference()
'/* testArrowFunctionReturnByReference */',
true,
],
[
'/* testClosureReturnByReference */',
true,
],
];
}
}
3 changes: 0 additions & 3 deletions Tests/Utils/Operators/IsReferenceDiffTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ if ($foo) {}
/* testTokenizerIssue1284PHPCSlt280C */
if ($foo) {}
[&$a, $b];

/* testClosureReturnByReference */
$closure = function &($param) use ($value) {};
4 changes: 0 additions & 4 deletions Tests/Utils/Operators/IsReferenceDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public function dataIsReference()
'/* testTokenizerIssue1284PHPCSlt280C */',
true,
],
'closure-return-by-reference' => [
'/* testClosureReturnByReference */',
true,
],
];
}
}