Skip to content

Commit 87ca29d

Browse files
authored
Merge pull request #195 from PHPCSStandards/phpcs-4.x/t_use-parenthesis-owner-initial-changes
PHPCS 4.x | Initial updates to handle T_USE becoming a parentheses owner
2 parents e8da419 + 2148118 commit 87ca29d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

PHPCSUtils/Utils/Operators.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ public static function isReference(File $phpcsFile, $stackPtr)
124124
if ($lastOpener !== false) {
125125
$lastOwner = Parentheses::getOwner($phpcsFile, $lastOpener);
126126

127-
if (isset(Collections::functionDeclarationTokensBC()[$tokens[$lastOwner]['code']]) === true) {
127+
if (isset(Collections::functionDeclarationTokensBC()[$tokens[$lastOwner]['code']]) === true
128+
// As of PHPCS 4.x, `T_USE` is a parenthesis owner.
129+
|| $tokens[$lastOwner]['code'] === \T_USE
130+
) {
128131
$params = FunctionDeclarations::getParameters($phpcsFile, $lastOwner);
129132
foreach ($params as $param) {
130133
if ($param['reference_token'] === $stackPtr) {

Tests/BackCompat/BCTokens/ParenthesisOpenersTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use PHP_CodeSniffer\Util\Tokens;
1414
use PHPCSUtils\BackCompat\BCTokens;
15+
use PHPCSUtils\BackCompat\Helper;
1516
use PHPUnit\Framework\TestCase;
1617

1718
/**
@@ -33,6 +34,7 @@ class ParenthesisOpenersTest extends TestCase
3334
*/
3435
public function testParenthesisOpeners()
3536
{
37+
$version = Helper::getVersion();
3638
$expected = [
3739
\T_ARRAY => \T_ARRAY,
3840
\T_LIST => \T_LIST,
@@ -49,6 +51,10 @@ public function testParenthesisOpeners()
4951
\T_DECLARE => \T_DECLARE,
5052
];
5153

54+
if (\version_compare($version, '4.0.0', '>=') === true) {
55+
$expected[\T_USE] = \T_USE;
56+
}
57+
5258
\asort($expected);
5359

5460
$result = BCTokens::parenthesisOpeners();

0 commit comments

Comments
 (0)