Skip to content

Commit

Permalink
Merge d8c067b into 3220fbd
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Sep 5, 2020
2 parents 3220fbd + d8c067b commit 67c83c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
18 changes: 4 additions & 14 deletions PHPCSUtils/Utils/Operators.php
Expand Up @@ -130,23 +130,13 @@ public static function isReference(File $phpcsFile, $stackPtr)
return true;
}
}
} elseif (isset($tokens[$lastOpener]['parenthesis_owner']) === false) {
$prev = false;
for ($t = ($lastOpener - 1); $t >= 0; $t--) {
if ($tokens[$t]['code'] !== \T_WHITESPACE) {
$prev = $t;
break;
}
}

if ($prev !== false && $tokens[$prev]['code'] === \T_USE) {
// Closure use by reference.
return true;
}
}
}

// Pass by reference in function calls and assign by reference in arrays.
/*
* Pass by reference in function calls, assign by reference in arrays and
* closure use by reference in PHPCS 2.x and 3.x.
*/
if ($tokens[$tokenBefore]['code'] === \T_OPEN_PARENTHESIS
|| $tokens[$tokenBefore]['code'] === \T_COMMA
|| $tokens[$tokenBefore]['code'] === \T_OPEN_SHORT_ARRAY
Expand Down
6 changes: 6 additions & 0 deletions Tests/BackCompat/BCFile/IsReferenceTest.inc
Expand Up @@ -163,6 +163,12 @@ functionCall( $something , &new Foobar() );
/* testUseByReference */
$closure = function() use (&$var){};

/* testUseByReferenceWithCommentFirstParam */
$closure = function() use /*comment*/ (&$this->value){};

/* testUseByReferenceWithCommentSecondParam */
$closure = function() use /*comment*/ ($varA, &$varB){};

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

Expand Down
8 changes: 8 additions & 0 deletions Tests/BackCompat/BCFile/IsReferenceTest.php
Expand Up @@ -308,6 +308,14 @@ public function dataIsReference()
'/* testUseByReference */',
true,
],
[
'/* testUseByReferenceWithCommentFirstParam */',
true,
],
[
'/* testUseByReferenceWithCommentSecondParam */',
true,
],
[
'/* testArrowFunctionReturnByReference */',
true,
Expand Down

0 comments on commit 67c83c9

Please sign in to comment.