Skip to content

Commit 6b1bdda

Browse files
committed
Replace findContainingOpeningBracket
1 parent 6a30e89 commit 6b1bdda

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

VariableAnalysis/Lib/Helpers.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use VariableAnalysis\Lib\VariableInfo;
1212
use PHP_CodeSniffer\Util\Tokens;
1313
use PHPCSUtils\Utils\Context;
14+
use PHPCSUtils\Utils\Parentheses;
1415

1516
class Helpers
1617
{
@@ -91,15 +92,11 @@ public static function getPreviousStatementPtr(File $phpcsFile, $stackPtr)
9192
*/
9293
public static function findContainingOpeningBracket(File $phpcsFile, $stackPtr)
9394
{
94-
$tokens = $phpcsFile->getTokens();
95-
if (isset($tokens[$stackPtr]['nested_parenthesis'])) {
96-
/**
97-
* @var list<int|string>
98-
*/
99-
$openPtrs = array_keys($tokens[$stackPtr]['nested_parenthesis']);
100-
return (int)end($openPtrs);
101-
}
102-
return null;
95+
// Use PHPCSUtils to get the innermost parenthesis opener
96+
$result = Parentheses::getLastOpener($phpcsFile, $stackPtr);
97+
98+
// PHPCSUtils returns false on failure, but our code expects null
99+
return $result !== false ? $result : null;
103100
}
104101

105102
/**

0 commit comments

Comments
 (0)